Imports System
Imports System.Drawing
Imports System.Windows.Forms
Namespace MouseEvent
' Summary description for Form1.
Public NotInheritable Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents panel1 As System.Windows.Forms.Panel
Private mousePath As System.Drawing.Drawing2D.GraphicsPath
Public Shared Sub Main()
System.Windows.Forms.Application.Run(New Form1())
End Sub 'Main
Public Sub New()
mousePath = New System.Drawing.Drawing2D.GraphicsPath()
Me.panel1 = New System.Windows.Forms.Panel()
' Mouse Panel
Me.panel1.Anchor = System.Windows.Forms.AnchorStyles.Top Or _
System.Windows.Forms.AnchorStyles.Left Or _
System.Windows.Forms.AnchorStyles.Right
Me.panel1.BackColor = System.Drawing.SystemColors.ControlDark
Me.panel1.Location = New System.Drawing.Point(16, 160)
Me.panel1.Size = New System.Drawing.Size(664, 320)
End Sub 'New
Private Sub panel1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles panel1.MouseDown
' Update the mouse path with the mouse information
Dim mouseDownLocation As New Point(e.X, e.Y)
Dim eventString As String = Nothing
Select Case e.Button
Case MouseButtons.Left
eventString = "L"
Case MouseButtons.Right
eventString = "R"
Case MouseButtons.Middle
eventString = "M"
Case MouseButtons.XButton1
eventString = "X1"
Case MouseButtons.XButton2
eventString = "X2"
Case MouseButtons.None:
eventString = Nothing
End Select
If Not (eventString Is Nothing) Then
mousePath.AddString(eventString, FontFamily.GenericSerif, CInt(FontStyle.Bold), fontSize, mouseDownLocation, StringFormat.GenericDefault)
Else
mousePath.AddLine(mouseDownLocation, mouseDownLocation)
End If
panel1.Focus()
panel1.Invalidate()
End Sub
Private Sub panel1_MouseEnter(sender As Object, e As System.EventArgs) Handles panel1.MouseEnter
' Update the mouse event label to indicate the MouseEnter event occurred.
label1.Text = sender.GetType().ToString() + ": MouseEnter"
End Sub
Private Sub panel1_MouseHover(sender As Object, e As System.EventArgs) Handles panel1.MouseHover
' Update the mouse event label to indicate the MouseHover event occurred.
label1.Text = sender.GetType().ToString() + ": MouseHover"
End Sub
Private Sub panel1_MouseLeave(sender As Object, e As System.EventArgs) Handles panel1.MouseLeave
' Update the mouse event label to indicate the MouseLeave event occurred.
label1.Text = sender.GetType().ToString() + ": MouseLeave"
End Sub
Private Sub panel1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles panel1.MouseMove
' Update the mouse path that is drawn onto the Panel.
Dim mouseX As Integer = e.X
Dim mouseY As Integer = e.Y
mousePath.AddLine(mouseX, mouseY, mouseX, mouseY)
End Sub
Private Sub panel1_MouseWheel(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles panel1.MouseWheel
' Update the drawing based upon the mouse wheel scrolling.
Dim numberOfTextLinesToMove As Integer = e.Delta * SystemInformation.MouseWheelScrollLines / 120 ' WHEEL_DATA
Dim numberOfPixelsToMove As Integer = numberOfTextLinesToMove * fontSize
If numberOfPixelsToMove <> 0 Then
Dim translateMatrix As New System.Drawing.Drawing2D.Matrix()
translateMatrix.Translate(0, numberOfPixelsToMove)
mousePath.Transform(translateMatrix)
End If
panel1.Invalidate()
End Sub
Private Sub panel1_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles panel1.MouseUp
Dim mouseUpLocation = New System.Drawing.Point(e.X, e.Y)
' Show the number of clicks in the path graphic.
Dim numberOfClicks As Integer = e.Clicks
mousePath.AddString(" " + numberOfClicks.ToString(), _
FontFamily.GenericSerif, CInt(FontStyle.Bold), _
fontSize, mouseUpLocation, StringFormat.GenericDefault)
panel1.Invalidate()
End Sub
Private Sub panel1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles panel1.Paint
' Perform the painting of the Panel.
e.Graphics.DrawPath(System.Drawing.Pens.DarkRed, mousePath)
End Sub
Private Sub clearButton_Click(sender As Object, e As System.EventArgs) Handles clearButton.Click
' Clear the Panel display.
mousePath.Dispose()
mousePath = New System.Drawing.Drawing2D.GraphicsPath()
panel1.Invalidate()
End Sub
End Class 'Form1
End Namespace
Imports System.Drawing
Imports System.Windows.Forms
Namespace MouseEvent
' Summary description for Form1.
Public NotInheritable Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents panel1 As System.Windows.Forms.Panel
Private mousePath As System.Drawing.Drawing2D.GraphicsPath
Public Shared Sub Main()
System.Windows.Forms.Application.Run(New Form1())
End Sub 'Main
Public Sub New()
mousePath = New System.Drawing.Drawing2D.GraphicsPath()
Me.panel1 = New System.Windows.Forms.Panel()
' Mouse Panel
Me.panel1.Anchor = System.Windows.Forms.AnchorStyles.Top Or _
System.Windows.Forms.AnchorStyles.Left Or _
System.Windows.Forms.AnchorStyles.Right
Me.panel1.BackColor = System.Drawing.SystemColors.ControlDark
Me.panel1.Location = New System.Drawing.Point(16, 160)
Me.panel1.Size = New System.Drawing.Size(664, 320)
End Sub 'New
Private Sub panel1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles panel1.MouseDown
' Update the mouse path with the mouse information
Dim mouseDownLocation As New Point(e.X, e.Y)
Dim eventString As String = Nothing
Select Case e.Button
Case MouseButtons.Left
eventString = "L"
Case MouseButtons.Right
eventString = "R"
Case MouseButtons.Middle
eventString = "M"
Case MouseButtons.XButton1
eventString = "X1"
Case MouseButtons.XButton2
eventString = "X2"
Case MouseButtons.None:
eventString = Nothing
End Select
If Not (eventString Is Nothing) Then
mousePath.AddString(eventString, FontFamily.GenericSerif, CInt(FontStyle.Bold), fontSize, mouseDownLocation, StringFormat.GenericDefault)
Else
mousePath.AddLine(mouseDownLocation, mouseDownLocation)
End If
panel1.Focus()
panel1.Invalidate()
End Sub
Private Sub panel1_MouseEnter(sender As Object, e As System.EventArgs) Handles panel1.MouseEnter
' Update the mouse event label to indicate the MouseEnter event occurred.
label1.Text = sender.GetType().ToString() + ": MouseEnter"
End Sub
Private Sub panel1_MouseHover(sender As Object, e As System.EventArgs) Handles panel1.MouseHover
' Update the mouse event label to indicate the MouseHover event occurred.
label1.Text = sender.GetType().ToString() + ": MouseHover"
End Sub
Private Sub panel1_MouseLeave(sender As Object, e As System.EventArgs) Handles panel1.MouseLeave
' Update the mouse event label to indicate the MouseLeave event occurred.
label1.Text = sender.GetType().ToString() + ": MouseLeave"
End Sub
Private Sub panel1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles panel1.MouseMove
' Update the mouse path that is drawn onto the Panel.
Dim mouseX As Integer = e.X
Dim mouseY As Integer = e.Y
mousePath.AddLine(mouseX, mouseY, mouseX, mouseY)
End Sub
Private Sub panel1_MouseWheel(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles panel1.MouseWheel
' Update the drawing based upon the mouse wheel scrolling.
Dim numberOfTextLinesToMove As Integer = e.Delta * SystemInformation.MouseWheelScrollLines / 120 ' WHEEL_DATA
Dim numberOfPixelsToMove As Integer = numberOfTextLinesToMove * fontSize
If numberOfPixelsToMove <> 0 Then
Dim translateMatrix As New System.Drawing.Drawing2D.Matrix()
translateMatrix.Translate(0, numberOfPixelsToMove)
mousePath.Transform(translateMatrix)
End If
panel1.Invalidate()
End Sub
Private Sub panel1_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles panel1.MouseUp
Dim mouseUpLocation = New System.Drawing.Point(e.X, e.Y)
' Show the number of clicks in the path graphic.
Dim numberOfClicks As Integer = e.Clicks
mousePath.AddString(" " + numberOfClicks.ToString(), _
FontFamily.GenericSerif, CInt(FontStyle.Bold), _
fontSize, mouseUpLocation, StringFormat.GenericDefault)
panel1.Invalidate()
End Sub
Private Sub panel1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles panel1.Paint
' Perform the painting of the Panel.
e.Graphics.DrawPath(System.Drawing.Pens.DarkRed, mousePath)
End Sub
Private Sub clearButton_Click(sender As Object, e As System.EventArgs) Handles clearButton.Click
' Clear the Panel display.
mousePath.Dispose()
mousePath = New System.Drawing.Drawing2D.GraphicsPath()
panel1.Invalidate()
End Sub
End Class 'Form1
End Namespace