2013-06-21 89 views
0

下面顯示的相應MouseDown事件(C#)的等效vb.net代碼是什麼?我應該如何在vb.net中實現這個事件?Vb.net相當於C#

謝謝你在前進,Goicox

var model = new PlotModel("MouseDown HitTestResult", "Reports the index of the nearest point."); 

var s1 = new LineSeries(); 
s1.Points.Add(new DataPoint(0, 10)); 
s1.Points.Add(new DataPoint(10, 40)); 
s1.Points.Add(new DataPoint(40, 20)); 
s1.Points.Add(new DataPoint(60, 30)); 
model.Series.Add(s1); 
s1.MouseDown += (s, e) => 
      { 
       model.Subtitle = "Index of nearest point in LineSeries: " + Math.Round(e.HitTestResult.Index); 
       model.InvalidatePlot(false); 
      }; 
+7

標題很有趣。 –

+1

使用redgate反射器將代碼從CLR語言轉換爲VB/C#/ C++,反之亦然。 http://www.red-gate.com/products/dotnet-development/reflector/ – ApolloSoftware

+0

該事件在.NET代碼中定義,C#和VB都建立在.NET代碼之上。該事件將存在於VB中具有相同名稱的同一個類。 – Servy

回答

1

簡單皈依應該這樣做:

Dim model = New PlotModel("MouseDown HitTestResult", "Reports the index of the nearest point.") 

Dim s1 = New LineSeries() 
s1.Points.Add(New DataPoint(0, 10)) 
s1.Points.Add(New DataPoint(10, 40)) 
s1.Points.Add(New DataPoint(40, 20)) 
s1.Points.Add(New DataPoint(60, 30)) 
model.Series.Add(s1) 
s1.MouseDown += Function(s, e) 
model.Subtitle = "Index of nearest point in LineSeries: " &   Math.Round(e.HitTestResult.Index) 
model.InvalidatePlot(False) 

End Function 

來源:http://www.developerfusion.com/tools/convert/csharp-to-vb/

+0

,我得到了以下錯誤:錯誤「公共事件MouseDown(發送者爲對象,E作爲OxyPlot.OxyMouseEventArgs)」是一個事件,而不能直接調用。使用'RaiseEvent'語句來引發一個事件。 – goicox

+0

其實我這是工作如下:AddHandler的s1.MouseDown,AddressOf Me.LSMouseDown – goicox

+0

那是因爲你無法轉換聲明。您需要使用Addhandler語句並將該事件連接到您製作的子例程。就像Idle_Mind所說。 – OneFineDay

0

你需要使用VB '子' 拉姆達(可在VS 2010及以後):

AddHandler s1.MouseDown, Sub(s, e) 
    model.Subtitle = "Index of nearest point in LineSeries: " & Math.Round(e.HitTestResult.Index) 
    model.InvalidatePlot(False) 
    End Sub