C# 到 VB 地址

标签 c# vb.net

我更喜欢 VB 而不是 C#,所以我在 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.MouseGestureEntered 它说:

公共(public)事件 MouseGestureEntered(sender As Object, e As DcamMouseGesture.MouseGestureEventArgs)' 是一个事件,不能直接调用。使用“RaiseEvent”语句引发事件。

我需要将它转换成什么才能在 VB 中工作?

最佳答案

代替:

_mg.MouseGestureEntered += New MouseGestureEventHandler(AddressOf OnMouseGestureEntered)

尝试使用:

AddHandler _mg.MouseGestureEntered, AddressOf OnMouseGestureEntered

关于C# 到 VB 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14330532/

相关文章:

vb.net - 计时器内标签

mysql - 2个表同时插入数据的方法

c# 如何更快地运行应用程序

c# - 不支持的源或模板图像的像素格式。 AForge影像

c# - 如何通过 C# 使用 CryptoAPI?

vb.net - 切换按钮控制

c# - 突然我的 web-api 项目找不到对 System.Web.Mvc 的引用,编译正常但运​​行时错误

c# - 如何选择从泛型方法调用的正确的 C# 重载扩展方法

c# - 添加两个 .NET SqlDecimals 会提高精度吗?

vb.net - 在 VB.NET 中将列表中的项目与同一列表中的其他项目进行比较