MouseDown和MoveUp事件的参数中都有哪个鼠标键被按下的参数: Private Sub Object_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)End SubPrivate Sub Object_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)End Sub Button Returns an integer that identifies the button that was pressed (MouseDown) or released (MouseUp) to cause the event. The button argument is a bit field with bits corresponding to the left button (bit 0), right button (bit 1), and middle button (bit 2). These bits correspond to the values 1, 2, and 4, respectively. Only one of the bits is set, indicating the button that caused the event. Constant (Button) Value Description vbLeftButton 1 Left button is pressed vbRightButton 2 Right button is pressed vbMiddleButton 4 Middle button is pressed
如jadeluo(秀峰) 所说,VB给出的窗体或控件的MouseDown和MoveUp事件处理Sub,提供的参数可以直接拿来用的,就是Button参数,比如在 Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) End Sub 中判断,如果是1,就是左键;2,右键;3,就是两个键同时
给出示例代码:窗体上有按钮和LabelPrivate Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Select Case Button Case vbLeftButton Label1.Caption = "鼠标左键被按下" Case vbRightButton Label1.Caption = "鼠标右键被按下" End Select End SubPrivate Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Select Case Button Case vbLeftButton Label1.Caption = "鼠标左键被抬起" Case vbRightButton Label1.Caption = "鼠标右键被抬起" End Select End Sub
Public Declare Function ReleaseCapture Lib "user32" () As LongMouseEnter = (0 <= X) And (X <= Pic_Mail.Width) And (0 <= Y) And (Y <= Pic_Mail.Height) '计算鼠标的移动是否在Command1里面 If MouseEnter Then '鼠标已经进入 Me.Caption = "Mouse In Button!" SetCapture Pic_Mail.hWndElse '鼠标已经离开 Me.Caption = "Mouse Out!" ReleaseCaptureEnd If
Private Declare Function ReleaseCapture Lib "user32" () As Long Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long private sub picture1_mousemove(button as integer,x as singe,y as single,shift as integer)private sub pic_Mail_mousemove(button as integer,x as singe,y as single,shift as integer)MouseEnter = (0 <= X) And (X <= Pic_Mail.Width) And (0 <= Y) And (Y <= Pic_Mail.Height) '计算鼠标的移动是否在Command1里面 If MouseEnter Then '鼠标已经进入 Me.Caption = "Mouse In Button!" SetCapture Pic_Mail.hWndElse '鼠标已经离开 Me.Caption = "Mouse Out!" ReleaseCaptureEnd If end sub
Private Sub Object_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)End SubPrivate Sub Object_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)End Sub
Button
Returns an integer that identifies the button that was pressed (MouseDown) or released (MouseUp) to cause the event. The button argument is a bit field with bits corresponding to the left button (bit 0), right button (bit 1), and middle button (bit 2). These bits correspond to the values 1, 2, and 4, respectively. Only one of the bits is set, indicating the button that caused the event. Constant (Button) Value Description
vbLeftButton 1 Left button is pressed
vbRightButton 2 Right button is pressed
vbMiddleButton 4 Middle button is pressed
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
End Sub
中判断,如果是1,就是左键;2,右键;3,就是两个键同时
Select Case Button
Case vbLeftButton
Label1.Caption = "鼠标左键被按下"
Case vbRightButton
Label1.Caption = "鼠标右键被按下"
End Select
End SubPrivate Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case Button
Case vbLeftButton
Label1.Caption = "鼠标左键被抬起"
Case vbRightButton
Label1.Caption = "鼠标右键被抬起"
End Select
End Sub
比如我要编写picturebox的testmousemove事件,具体的代码应该怎样写?
要求参数暂时就和mousemove一样罢,功能也类似。
(是相对picturebox的,用currentx、currenty好像不行.)
If MouseEnter Then '鼠标已经进入
Me.Caption = "Mouse In Button!"
SetCapture Pic_Mail.hWndElse '鼠标已经离开 Me.Caption = "Mouse Out!"
ReleaseCaptureEnd If
Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
private sub picture1_mousemove(button as integer,x as singe,y as single,shift as integer)private sub pic_Mail_mousemove(button as integer,x as singe,y as single,shift as integer)MouseEnter = (0 <= X) And (X <= Pic_Mail.Width) And (0 <= Y) And (Y <= Pic_Mail.Height) '计算鼠标的移动是否在Command1里面
If MouseEnter Then '鼠标已经进入
Me.Caption = "Mouse In Button!"
SetCapture Pic_Mail.hWndElse '鼠标已经离开 Me.Caption = "Mouse Out!"
ReleaseCaptureEnd If
end sub