Option Strict On
imports System
imports System.Drawing
imports System.Windows.Forms
public class MouseEvents : inherits Form
private lbl as Label
private WithEvents btnReset as Button
public sub New()
Size = new Size(400,600)
btnReset = new Button()
btnReset.Parent = me
btnReset.Location = new Point(250,50)
btnReset.Text = "Reset"
lbl = new Label()
lbl.Parent = me
lbl.Location = new Point(50,50)
lbl.Size = new Size(250,250)
lbl.BorderStyle = BorderStyle.Fixed3D
AddHandler lbl.MouseEnter, AddressOf lbl_MouseEnter
AddHandler lbl.MouseHover, AddressOf lbl_MouseHover
AddHandler lbl.MouseLeave, AddressOf lbl_MouseLeave
AddHandler lbl.MouseDown, AddressOf lbl_MouseDown
AddHandler lbl.MouseMove, AddressOf lbl_MouseMove
AddHandler lbl.MouseUp, AddressOf lbl_MouseUp
AddHandler lbl.MouseWheel, AddressOf lbl_MouseWheel
AddHandler lbl.Click, AddressOf lbl_Click
AddHandler lbl.DoubleClick, AddressOf lbl_DoubleClick
end sub
public shared sub Main()
Application.Run(new MouseEvents())
end sub
private sub btnReset_Click(ByVal sender as object, _
ByVal e as EventArgs) _
Handles btnReset.Click
lbl.Text = ""
end sub
private sub lbl_MouseEnter(ByVal sender as object, _
ByVal e as EventArgs)
lbl.Text = "MouseEnter"
Console.WriteLine("Label MouseEnter")
end sub
private sub lbl_MouseHover(ByVal sender as object, _
ByVal e as EventArgs)
lbl.Text = "MouseHover"
Console.WriteLine("Label MouseHover")
end sub
private sub lbl_MouseLeave(ByVal sender as object, _
ByVal e as EventArgs)
lbl.Text = "MouseLeave"
Console.WriteLine("Label MouseLeave")
end sub
private sub lbl_MouseDown(ByVal sender as object, _
ByVal e as MouseEventArgs)
lbl.Text = "MouseDown"
Console.WriteLine("Label MouseDown")
Console.WriteLine("Button: " + e.Button.ToString())
Console.WriteLine("Clicks: " + e.Clicks.ToString())
Console.WriteLine("Delta: " + e.Delta.ToString())
Console.WriteLine("X: " + e.X.ToString())
Console.WriteLine("Y: " + e.Y.ToString())
end sub
private sub lbl_MouseMove(ByVal sender as object,ByVal e as MouseEventArgs)
lbl.Text = "MouseMove"
Console.WriteLine("Label MouseMove")
Console.WriteLine("Button: " + e.Button.ToString())
Console.WriteLine("Clicks: " + e.Clicks.ToString())
Console.WriteLine("Delta: " + e.Delta.ToString())
Console.WriteLine("X: " + e.X.ToString())
Console.WriteLine("Y: " + e.Y.ToString())
end sub
private sub lbl_MouseUp(ByVal sender as object, _
ByVal e as MouseEventArgs)
lbl.Text = "MouseUp"
Console.WriteLine("Label MouseUp")
Console.WriteLine("Button: " + e.Button.ToString())
Console.WriteLine("Clicks: " + e.Clicks.ToString())
Console.WriteLine("Delta: " + e.Delta.ToString())
Console.WriteLine("X: " + e.X.ToString())
Console.WriteLine("Y: " + e.Y.ToString())
end sub
private sub lbl_MouseWheel(ByVal sender as object,ByVal e as MouseEventArgs)
lbl.Text = "MouseWheel"
Console.WriteLine("Label MouseWheel")
Console.WriteLine("Button: " + e.Button.ToString())
Console.WriteLine("Clicks: " + e.Clicks.ToString())
Console.WriteLine("Delta: " + e.Delta.ToString())
Console.WriteLine("X: " + e.X.ToString())
Console.WriteLine("Y: " + e.Y.ToString())
end sub
private sub lbl_Click(ByVal sender as object,ByVal e as EventArgs)
lbl.Text = "Click"
Console.WriteLine("Label Click")
end sub
private sub lbl_DoubleClick(ByVal sender as object,ByVal e as EventArgs)
lbl.Text = "DoubleClick"
Console.WriteLine("Label DoubleClick")
end sub
protected overrides sub OnMouseEnter(ByVal e as EventArgs)
myBase.OnMouseEnter(e)
Console.WriteLine("Form MouseEnter")
end sub
protected overrides sub OnMouseHover(ByVal e as EventArgs)
myBase.OnMouseHover(e)
Console.WriteLine("Form MouseHover")
end sub
protected overrides sub OnMouseLeave(ByVal e as EventArgs)
myBase.OnMouseLeave(e)
Console.WriteLine("Form MouseLeave")
end sub
end class