|
-
May 12th, 2003, 01:44 PM
#1
Thread Starter
Frenzied Member
Which control is under the mouse?
I was thinking of the way to detect which control is under the mouse. I couldnt find an easy way.
I think it can be done by:
1-Detecting the mouse position.
2-Looping through the controls of the form and if the mouse position falls in the bounds of the control then the mouse is on that control.
But this is a little time consuming and not desireable esp in a very populated form. Any better idea?
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
May 12th, 2003, 01:49 PM
#2
write a mousehover event and wire up the mousehover event of all controls to it. sender parameter will be the control that the mouse is over.
Code:
Private Sub MouseHover1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseHover, Label1.MouseHover
MessageBox.Show(sender.Name)
End Sub
-
May 12th, 2003, 01:51 PM
#3
Excuse me. MouseEnter might be better than MouseHover
-
May 12th, 2003, 02:04 PM
#4
Thread Starter
Frenzied Member
Thanks Cander
I was thinking to make it more dynamic, and that was looping through all controls at form_load event and addhandler for their Mouse_Enter event. What you think about that?
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
May 12th, 2003, 02:07 PM
#5
i was actually looking into that. I m tryin to create a loop that goes through each control on the form then adds the handler to it. Sorta like this
VB Code:
Dim a As Object
For Each a In Me.Controls
If a.GetType.ToString() <> "Form" Then
AddHandler CType(a, a.GetType).MouseEnter, AddressOf MouseHover1
End If
Next
Problem is, it wont accept the a.GeType from within the CType function
-
May 12th, 2003, 02:09 PM
#6
if nothing else, you could Select Case the a.GetType.ToString for things like Button, Label, etc. and just do a CType(a, Button).MouseEnter for Button, same for label, etc.
-
May 12th, 2003, 02:12 PM
#7
Thread Starter
Frenzied Member
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
May 12th, 2003, 02:14 PM
#8
I didnt want it to Messagebox everytime i moved the mouse. No other reason
-
May 12th, 2003, 02:16 PM
#9
oh boy..I figured it out
VB Code:
For Each a In Me.Controls
AddHandler CType(a, Control).MouseEnter, AddressOf MouseHover1
Next
-
May 12th, 2003, 02:21 PM
#10
Thread Starter
Frenzied Member
I didnt want it to Messagebox everytime i moved the mouse. No other reason
I need to send the control which is under the mouse to another event and that inclueds the 'Form' itslef. By the way the form itself is not included in its control collections. So I should write the event for the form that hanles MyBase.MouseEnter and address all of other controls to that event.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
May 12th, 2003, 02:28 PM
#11
Well since form is just 1 object, I see no reason why shouldnt just straight code in the Forms MouseWhatever event. And use the wired up event for all other controls.
-
May 12th, 2003, 02:31 PM
#12
Thread Starter
Frenzied Member
Thats just what i meant, write the event for form and
AddHandler CType(a, Control).MouseEnter, AddressOf Form1_MouseEnter
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|