Reputation: 10542
I'm more of a VB guy than c# so i have this code in 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() ) );
}
This is what i can come up with from 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
Problem being is the line _mg.MouseGestureEntered its saying:
Public Event MouseGestureEntered(sender As Object, e As DcamMouseGesture.MouseGestureEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.
What would i need to convert it to in order for it to work in VB?
Upvotes: 1
Views: 680
Reputation: 1358
Instead of:
_mg.MouseGestureEntered += New MouseGestureEventHandler(AddressOf OnMouseGestureEntered)
Try using:
AddHandler _mg.MouseGestureEntered, AddressOf OnMouseGestureEntered
Upvotes: 6