vb 鼠标放在图片上换图片

来源:百度知道 编辑:UC知道 时间:2024/05/18 00:03:30
其实我是想 实现按钮的功能.

把当鼠标移到 一个 图片上时这个图片换成另一张,移走时又换回来!!

不管用什么方法只要是在图片上实现就OK.
鼠标移走的时候 它不会变啊?!?!?!

新建一个资源文件,添加两个位图资源,资源号分别为101,102.

Private Sub Form_Load()
Picture1.Picture = LoadResPicture(102, 0)
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.Picture = LoadResPicture(102, 0)
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.Picture = LoadResPicture(101, 0)
End Sub

'---如果还要区分按下和普通状态可以加入picture1_mousedown和mouseup过程。

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, Shift As Integer, X As Single, Y As Single)
With Picture1
If (X < 0) Or (Y < 0) Or (X > .Width) Or (Y > .Height) Then
ReleaseCapture
Picture1.Picture = A.Picture '鼠标移出了
Else
SetCapture .hwnd<