vb 怎么写鼠标移动事件

来源:百度知道 编辑:UC知道 时间:2024/09/21 03:27:57
现有一个image控件,当鼠标移到该控件时,变换另一图像,鼠标移开,又变回原图像,求代码
第一个回答太简单,第二个回答经测试,移进去可以,移出去后不能还原原图像

Private Sub image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'鼠标在image上移动
image1.picture = loadpicture("c:\2.bmp")
End Sub
Private Sub form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
’鼠标离开image,在窗体上移动
image1.picture = loadpicture("c:\1.bmp")
End Sub

Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long

4) 在Command1的MouseMove事件中编写以下代码:
Private Sub image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim MouseEnter As Boolean '鼠标进入的标志位

MouseEnter = (0 <= X) And (X <= image1.Width) And (0 <= Y) And (Y <=
Command1.Height) '计算鼠标的移动是否在image1里面
If MouseEnter Then '鼠标已经进入
set image1.picture = loadpicture(&q