2013年(4)
分类: WINDOWS
2013-09-30 12:44:14
在VB程序中直接添加程序段
Private Sub HomeForm_MouseDown(ByVal Sender As Object, ByVal MouseOper As MouseEventArgs) Handles Me.MouseDown
If MouseOper.Button = Windows.Forms.MouseButtons.Right Then
Dim MouseX As Single = MouseOper.X
Dim MouseY As Single = MouseOper.Y
MsgBox("mouse location:" & vbCrLf & "X:" & MouseX & "Y:" & MouseY, vbOKOnly, "Location")
End if
End sub
说明:
1. Handles:操作钩子。VB.net中所有的操作均必须有操作钩子。钩子中指定工具范围,比如这里是Me,也可以是其他工具的名称,后面指定操作为MouseDown或者MouseUp。
2. MouseOper指向了鼠标操作事件,button可以获得单击的为左键或者右键。Click记录了鼠标单击的次数。Location保存了鼠标操作时的位置。MouseOper.X记录鼠标操作的横坐标。
3. Windows.Forms.MouseButtons.Right指向了鼠标右键
4. vbCrLf为vb中指向的换行和回车符。