Home > Software engineering >  I want to made a picture control button, the mouse point to he loaded the other picture, after reduc
I want to made a picture control button, the mouse point to he loaded the other picture, after reduc

Time:09-26

I want to made a picture control button, the mouse point to he loaded the other picture, to restore the original after you remove the picture
Private Sub PictureA01_MouseMove (Button As an Integer, Shift the As an Integer, As Single X, Y As Single)
If 1 & lt;=X And X & lt;=PictureA01. Width And 1 & lt;=Y And Y & lt;=PictureA01. Height Then
AppPath=App. Path & amp; "\ img \ Menu1-1. JPG"
PictureA01. Picture=LoadPicture (appPath)
The Else
AppPath=App. Path & amp; "\ img \ Menu1 JPG"
PictureA01. Picture=LoadPicture (appPath)
End the If
End Sub
Above is my writing, but it must be wrong, I don't know what to do, online said those methods cannot be fully realized my results

CodePudding user response:

This code you must not, on "the mouse out" basically cannot correct response,
Consider this code:
 Option Explicit 

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

Private mlPicFlag As Long

Private Sub Form_Load ()
Picture1. Picture=LoadPicture (" E: \ Temp \ 1. JPG ")
MlPicFlag=0 & amp;
End Sub

Private Sub Picture1_MouseMove (Button As an Integer, Shift the As an Integer, As Single X, Y As Single)
Dim cx& Cy& IFlag&

If (0=mlPicFlag) Then
Picture1. Picture=LoadPicture (" E: \ Temp \ 2. JPG ")
Call SetCapture (Picture1. HWnd)
MlPicFlag=1
The Else
Cx=X: cy=Y
IFlag=1
Do
If (cx & lt; 0) Then Exit the Do
If (cy & lt; 0) Then Exit the Do
If (cx & gt; Picture1. Width) Then Exit the Do
If (cy & gt; Picture1. Height) Then Exit the Do
IFlag=0: Exit Do
Loop
If (iFlag) Then
MlPicFlag=0
Call ReleaseCapture
Picture1. Picture=LoadPicture (" E: \ Temp \ 1. JPG ")
End the If
End the If
End Sub

CodePudding user response:

Picture not the mouse to the event, so have to write their own,

Use a timer, API to get the coordinates of the mouse, to form the coordinates,
Determine whether, in the Picture
Then the transformation background,
  •  Tags:  
  • API
  • Related