2013-01-15 23 views
1

我更多的是VB的人比C#的,所以我有這樣的代碼在C#:C#VB的AddressOf

MouseGesture _mg; 

    public Form1() 
    { 
     InitializeComponent(); 

     // b) Load a file with the commands and keys once in your application 
     MouseGestureData.Instance.Commands.ReadFile( 
      Environment.CurrentDirectory + @"\MouseGestureCommands.xml"); 

     // c) For each Form you want to use mouse gestures... 
     _mg = new MouseGesture(this, null); 
     _mg.MouseGestureEntered += new MouseGestureEventHandler( 
      OnMouseGestureEntered); 
    } 

    private void OnMouseGestureEntered(object sender, MouseGestureEventArgs e) 
    { 
     // d) In your registered MouseGestureEventHandler, handle the commands 
     // you want 
     MessageBox.Show(string.Format("OnMouseGestureEntered:\n" + 
             " Command:\t{0}\n" + 
             " Key:\t\t{1}\n" + 
             " Control:\t\t{2}\n" + 
             " Bounds:\t\t{3}", 
             e.Command, e.Key, e.Control, 
             e.Bounds.ToString())); 
    } 

這是我可以從VB.net拿出:

Private _mg As MouseGesture 

Public Sub New() 
    InitializeComponent() 

    MouseGestureData.Instance.Commands.ReadFile(Environment.CurrentDirectory + "\MouseGestureCommands.xml") 

    _mg = New MouseGesture(Me, Nothing) 
    _mg.MouseGestureEntered += New MouseGestureEventHandler(AddressOf OnMouseGestureEntered) 
End Sub 

Private Sub OnMouseGestureEntered(sender As Object, e As MouseGestureEventArgs) 
    ' d) In your registered MouseGestureEventHandler, handle the commands 
    ' you want 
    MessageBox.Show(String.Format("OnMouseGestureEntered:" & vbLf & " Command:" & vbTab & "{0}" & vbLf & " Key:" & vbTab & vbTab & "{1}" & vbLf & " Control:" & vbTab & vbTab & "{2}" & vbLf & " Bounds:" & vbTab & vbTab & "{3}", e.Command, e.Key, e.Control, e.Bounds.ToString())) 
End Sub 

問題的存在是該行_mg.MouseGestureEntered的說法:

公共事件MouseGestureEntered(發送者爲對象,E作爲DcamMouseGesture.MouseGest ureEventArgs)'是一個事件,不能直接調用。使用'RaiseEvent'語句來引發一個事件。

我需要什麼將它轉換爲它在VB中工作?

+1

順便說一句,你可能會發現這個工具非常有用:http://www.developerfusion.com/tools/convert/vb-to- csharp/ –

+0

我個人覺得這個更好:http://www.codechanger.com/ –

回答

6

相反的:

_mg.MouseGestureEntered += New MouseGestureEventHandler(AddressOf OnMouseGestureEntered) 

嘗試使用:

AddHandler _mg.MouseGestureEntered, AddressOf OnMouseGestureEntered 
+1

參考:http://msdn.microsoft.com/en-us/library/6yyk8z93(v=vs.90).aspx – Inisheer

+0

就是這樣!謝謝xfx! – StealthRT

+0

很高興爲您提供幫助@StealthRT – xfx