Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opposite of a 'mousemove' event.

Status
Not open for further replies.

basepointdesignz

Programmer
Joined
Jul 23, 2002
Messages
566
Location
GB
What's the opposite to a 'mousemove' event??

On the Mainpage of my application, I have labels for each command button, explaining what the form (that it opens)will do or help do. What I want to do is when the mouse moves over the label, the caption changes to another text string which will further explain the form's function and then return to the original caption when the mouse is moved away. So, in short, the caption says one thing as default (mouse not near) and then says something elase when the mouse is on/over it.

Any ideas and/or code samples please!?!?
 
Well, the label will only get MouseMove events when the mous is over it, so plan 1 would be simply to have the text change the caption upon detection of a mouse move. Of course, plan 1 falls down when you try to figure out how to detect that the mouse has moved out of the label again (Delphi, for example, has OnMouseEnter and OnMouseLeave events).

One relatively simple way is to detect a mouse move on your form, which means that the mouse can't be over any other controls (including your labels), and use that event to reset any label that is currently showing the more explicit data.

This isn't great, because the use may swiftly move the mouse to another control (or switch to another application)thus the form would miss out on getting a MouseMove event.

Now, I'm there's an API call that allows you to set a restrict mouse input to a slected window, which means that you could implement your own MouseEnter and MouseLeave functions - but it requires a handle to a window (hWnd), which a label doesn't have. Still, if you'd be prepared to consider a textbox, suitable set up to look like a label, then the following would be possible (you'll need a form with an array of textboxes). Also note that this is illustrative of one particular approach, not a full solution:
[tt]
Option Explicit

Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long


Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Debug.Print "Moving"
End Sub

Private Sub Text1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Static InTextBox As Boolean

If Not InTextBox Then
SetCapture Text1(Index).hwnd
InTextBox = True
ElseIf WindowFromPoint(X, Y) <> Text1(Index).hwnd Then
ReleaseCapture
InTextBox = False
End If
Text1(Index).Text = InTextBox
End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top