Imports System Imports System.Drawing Imports System.Windows.Forms Namespace MouseEventNamespace MouseEvent ' Summary description for Form1. PublicNotInheritableClass Form1Class Form1 Inherits System.Windows.Forms.Form FriendWithEvents panel1 As System.Windows.Forms.Panel Private mousePath As System.Drawing.Drawing2D.GraphicsPath PublicSharedSub Main()Sub Main() System.Windows.Forms.Application.Run(New Form1()) End Sub'Main PublicSub New()SubNew() 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 PrivateSub panel1_MouseDown()Sub panel1_MouseDown(sender AsObject, e As System.Windows.Forms.MouseEventArgs) Handles panel1.MouseDown ' Update the mouse path with the mouse information Dim mouseDownLocation AsNew Point(e.X, e.Y) Dim eventString AsString=Nothing SelectCase 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 EndSelect IfNot (eventString IsNothing) Then mousePath.AddString(eventString, FontFamily.GenericSerif, CInt(FontStyle.Bold), fontSize, mouseDownLocation, StringFormat.GenericDefault) Else mousePath.AddLine(mouseDownLocation, mouseDownLocation) EndIf panel1.Focus() panel1.Invalidate() End Sub PrivateSub panel1_MouseEnter()Sub panel1_MouseEnter(sender AsObject, 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 PrivateSub panel1_MouseHover()Sub panel1_MouseHover(sender AsObject, 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 PrivateSub panel1_MouseLeave()Sub panel1_MouseLeave(sender AsObject, 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 PrivateSub panel1_MouseMove()Sub panel1_MouseMove(sender AsObject, e As System.Windows.Forms.MouseEventArgs) Handles panel1.MouseMove ' Update the mouse path that is drawn onto the Panel. Dim mouseX AsInteger= e.X Dim mouseY AsInteger= e.Y mousePath.AddLine(mouseX, mouseY, mouseX, mouseY) End Sub PrivateSub panel1_MouseWheel()Sub panel1_MouseWheel(sender AsObject, e As System.Windows.Forms.MouseEventArgs) Handles panel1.MouseWheel ' Update the drawing based upon the mouse wheel scrolling. Dim numberOfTextLinesToMove AsInteger= e.Delta * SystemInformation.MouseWheelScrollLines /120' WHEEL_DATA Dim numberOfPixelsToMove AsInteger= numberOfTextLinesToMove * fontSize If numberOfPixelsToMove <>0Then Dim translateMatrix AsNew System.Drawing.Drawing2D.Matrix() translateMatrix.Translate(0, numberOfPixelsToMove) mousePath.Transform(translateMatrix) EndIf panel1.Invalidate() End Sub PrivateSub panel1_MouseUp()Sub panel1_MouseUp(sender AsObject, 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 AsInteger= e.Clicks mousePath.AddString(""+ numberOfClicks.ToString(), _ FontFamily.GenericSerif, CInt(FontStyle.Bold), _ fontSize, mouseUpLocation, StringFormat.GenericDefault) panel1.Invalidate() End Sub PrivateSub panel1_Paint()Sub panel1_Paint(sender AsObject, 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 PrivateSub clearButton_Click()Sub clearButton_Click(sender AsObject, 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