Click to See Complete Forum and Search --> : Mouse Cursor position
Eiredrake
May 25th, 2000, 09:34 PM
Basically I am trying to detect whether or not the cursor is over a particular control on the form.
Ie: If the cursor is over a Command Button, cause the command button to do something. (change images or whatever)
I know about how to query the API call to find out where the mouse is on the screen. And I can translate it into pixels and such. My question revolves basically around 'how do I tell where on the screen the cursor is relative to a control.'
Reason being that I am trying to create a custom control that performs an action when the Mouse is over it.
I KNOW there is a way to do it.. I just haven't found it yet. Any help will be much appreciated.
Thanks,
EireDrake
Bob724
May 25th, 2000, 10:35 PM
Most every control that you use in a form has a mousemove event that is called when the mouse is over the control. There are built-in parameters that come with the event called X and Y that return the position of the mouse over that particular control.
If there is a control that doesn't have that event, you can use the form's mousemove event. It will also return the X and Y position of the mouse when the mouse is over the form or any other control on the form. Then you can use the Left and Right properties of that control to compare the mouse position to the control's position and detect mouse movements that way.
Hope this helps
_____
Bob K.
Rob Brown
May 25th, 2000, 10:39 PM
You don't need to use any API to do this.
Place the code in the mouse_move event of the control ie:
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Command1.Caption = "My caption has changed"
End Sub
Hope this helps you out.
Best Regards,
Rob Brown.
Eiredrake
May 26th, 2000, 04:53 AM
Problem with that is... In order to get the control I am working on to display only once and only when the cursor is over the control. I'd need to have the MouseMove for the control fire while the mouse is over it 1 time (so that it's not repainting every 1/50 of a second) and then shut itself off.
Then when the cursor is not above the control, turn itself back to normal. To do that, I'd have to access the Form's MouseOver event which to my knowledge you can't do from inside a control.
Basically i am looking to make a custom command button, which highlights the text while the cursor is over it (in non-graphic mode) or changes it's picture (in graphic mode). I know that there are umpteen controls out there already made that do this... But <a> I don't trust 3rd party controls very much and <b> I want to be able to create one WITHOUT a border or WITH a border as I see fit.
Thanks,
EireDrake
Bob724
May 27th, 2000, 05:19 AM
Possibly...
It might sound kind of dinky, but is there anything wrong with:
1. Using the Form_Mouse_Move event to detect if the cursor is over the control
2. Once the cursor is over the control, do the code you want to do like making the text bold, and then begin checking for the cursor to be off of the control by means of setting a flag or whatever
3. Then once it's off again, do the other code to un-bold the text, and then start to check once more for the cursor to be on the control
4. Keep doing this forever...
I'm sure you're thinking that there's gotta be a better way, but I doubt it. Even if you do use an API to detect the position of the mouse, there has to be some event to trigger that API function, namely the Form_Mouse_Move event that I've been talking about. If you do find a way, though, let me know in another post on this thread.
Good Luck!
_______
Bob K.
Eiredrake
May 27th, 2000, 11:12 AM
The idea I had was based on a code packet that is up here... Which detects the screen X/Y position by firing a Timer event with an interval of 1.
My only question is... how do I use that value of X/Y to determine when the cursor is over the control.. IE: How to do check for that?
Eiredrake
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.