Last update May 7, 2010 up top

Mouse gesture's code by VB.NET 1.1

This code is more better than Mouse gesture's code by VB.NET. it's compatible with All-in-One Gestures. This version does not detect diagonal stroke.


Public Class Form1

	Dim gestureStarted As Boolean 
	Dim strokes As String 
	Dim exX, exY, grid As Integer 

	Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
		If e.Button = Windows.Forms.MouseButtons.Right Then 
			gestureStarted = True 
			grid = 15 
			strokes = "" 
			exX = e.X 
			exY = e.Y 
		End If
	End Sub

	Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
		If e.Button = Windows.Forms.MouseButtons.Right Then 
			gestureStarted = False 
			Select Case strokes 
				Case "DR" 
					End
				Case "RU" 
					If Me.WindowState = FormWindowState.Normal Then
						Me.WindowState = FormWindowState.Maximized
					Else
						Me.WindowState = FormWindowState.Normal
					End If
			End Select
		End If
	End Sub

	Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
		If gestureStarted Then
			Dim dirX, dirY, absX, absY As Integer 
			Dim pente As Single 
			Dim direction As String 

			'ToolStripStatusLabel1.Text = "Mouse gesture " & strokes

			dirX = e.X - exX : absX = Math.Abs(dirX)
			dirY = e.Y - exY : absY = Math.Abs(dirY)

			If absX < grid And absY < grid Then Return 

			If absY <= 5 Then pente = 100 Else pente = absX / absY
			If pente < 0.58 Or pente > 1.73 Then 
				If pente < 0.58 Then
					If dirY > 0 Then direction = "D" Else direction = "U"
				Else
					If dirX > 0 Then direction = "R" Else direction = "L"
				End If
				
				If Not strokes.EndsWith(direction) Then strokes = strokes & direction
			End If
			exX = e.X : exY = e.Y 
		End If
	End Sub

End Class