Click to See Complete Forum and Search --> : Subclassing


i54
January 30th, 2000, 07:28 PM
I'm working on a new usercontrol... its not very advanced, just some lines making a "3D Flat Button" which prints text to the center of it, i have the code to draw the lines pushed in... etc... but i want to know when the users moves the mouse "Off" of the control, once that has happend i want it to use the HideLines sub to hide the lines. how can i subclass my form to figure out the mouse has moved off of it, or any other code i can use other than a timer to figure out that the mouse has moved off the usercontrol completely.

vampyre
July 19th, 2000, 08:18 AM
Use the setcapture and ReleaseCapture API functions:

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

SetCapture directs all input from the mouse (including move messages) to the window specified in hWnd, and ReleaseCapture cancels that. So, if you place the following code in the mousemove event of your UserControl:

Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X >= 0 And X <= UserControl.ScaleWidth And Y >= 0 And Y <= UserControl.ScaleHeight Then
SetCapture UserControl.hWnd
'call whatever function you use if the mouse is over your control
Else
ReleaseCapture
'call whatever function you use if the mouse is not over your control
End If
End Sub

Because SetCapture directed all input from the mouse to your control from the moment the mouse moved over it, the mousemove event will continue to fire even when the mouse is no longer over the control, in which case the capture is released by the If-Then-Else statement in the sub. You can then use the sub to fire any function that blanks out the lines around your control.

I hope that helped. If you have any questions about this, you can mail me: lhellemons@hotmail.com

Good luck,

Vampyre

Un1
February 20th, 2001, 03:35 AM
http://www.banasoft.com/DownLoad/BNHkLib.exe