首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C#到VB AddressOf

C#到VB AddressOf
EN

Stack Overflow用户
提问于 2013-01-15 03:05:28
回答 1查看 629关注 0票数 1

比起c#,我更像一个VB的家伙,所以我在c#中有这样的代码:

代码语言:javascript
复制
    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得到的:

代码语言:javascript
复制
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.MouseGestureEventArgs)‘是一个事件,不能直接调用。使用“RaiseEvent”语句引发事件。

为了让它在VB中工作,我需要把它转换成什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-15 03:07:53

而不是:

代码语言:javascript
复制
_mg.MouseGestureEntered += New MouseGestureEventHandler(AddressOf OnMouseGestureEntered)

试着使用:

代码语言:javascript
复制
AddHandler _mg.MouseGestureEntered, AddressOf OnMouseGestureEntered
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14330532

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档