簡體   English   中英

C#到VB AddressOf

[英]C# to VB AddressOf

我比C#更像VB家伙,所以我在C#中有以下代碼:

    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.MouseGesture輸入了它的說法:

公共事件MouseGestureEntered(作為對象發送,作為DcamMouseGesture.MouseGestureEventArgs發送)是一個事件,不能直接調用。 使用“ RaiseEvent”語句引發事件。

為了在VB中工作,我需要將其轉換為什么?

代替:

_mg.MouseGestureEntered += New MouseGestureEventHandler(AddressOf OnMouseGestureEntered)

嘗試使用:

AddHandler _mg.MouseGestureEntered, AddressOf OnMouseGestureEntered

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM