我是一个比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.MouseGestureEntered 这句话:
公共事件MouseGestureEntered(发件人为对象,e为DcamMouseGesture.MouseGestureEventArgs)'是一个事件,不能直接调用。使用' RaiseEvent'发表活动的声明。
我需要将它转换为什么才能在VB中工作?
答案 0 :(得分:6)
而不是:
_mg.MouseGestureEntered += New MouseGestureEventHandler(AddressOf OnMouseGestureEntered)
尝试使用:
AddHandler _mg.MouseGestureEntered, AddressOf OnMouseGestureEntered