By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,247 Members | 1,165 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,247 IT Pros & Developers. It's quick & easy.

C# Event Bubbling & Mouse Position Woes

P: 3
I'm basically trying to implement a simple drop down menu list for a button that I have. When the user hovers over the button, I want a list of button options to appear below the button. If the users mouse leaves the button, or the buttons in the list I want the list to disappear.

I originally tried to place all of the drop down buttons into a single user control, and to then have them appear when users enter some button and disappear when the user leaves the button and drop down menu, but this doesn't work because the user control doesn't get the bubbled events. Instead the buttons in the menu intercept the events.

So then I decided that I could try to still work around this if I could get the mouse position in the mouse enter / leave events. I tried to do this by using PointToClient(Control.MousePosition). The values I'm getting though for the mouse position in screen space in my mouse leave events seem to be totally messed up though.

Does anyone have any ideas on how I can try to fix either the bubbling issue, or how to fix the mouse position? Thanks!
Dec 19 '07 #1
Share this Question
Share on Google+
5 Replies


P: 4
Why don't you just stick on a ContextMenuStrip when they right click?
Dec 19 '07 #2

P: 3
Why don't you just stick on a ContextMenuStrip when they right click?
I want this to be more like a menu system, I don't want people to have to right click. Plus I'm trying to use certain background images so that it matches my skin. Otherwise, I probably could have gotten away with a MenuStrip.
Dec 19 '07 #3

Plater
Expert 5K+
P: 7,872
Let me prefeace this section with a "I might have it backwards":
The mouse capture events that provide X Y coords for the mouse are already relative to your control on which event is fireing.
So if you listen for mouse movements on your button control, the X Y will be given relative to the top left corner of the button.
If you listen for mouse movements on your form, the X Y will be given relative to the top left corner of the form (not sure how the title bar factors in)



For your "buttons" I would suggest watching the mouseenter/exit functions to determine if the mouse is "over" your button or not.
Then based on the X Y you get, make visible your set of buttons, be sure to make sure they're "topmost" or whatever.


This *is* a windows application yes?
Dec 19 '07 #4

P: 3
Let me prefeace this section with a "I might have it backwards":
The mouse capture events that provide X Y coords for the mouse are already relative to your control on which event is fireing.
So if you listen for mouse movements on your button control, the X Y will be given relative to the top left corner of the button.
If you listen for mouse movements on your form, the X Y will be given relative to the top left corner of the form (not sure how the title bar factors in)
I don't think that's correct: http://msdn2.microsoft.com/en-us/lib...eposition.aspx

"A Point that contains the coordinates of the mouse cursor relative to the upper-left corner of the screen."

The PointToControl function I think converts to the local coordinate system.

For your "buttons" I would suggest watching the mouseenter/exit functions to determine if the mouse is "over" your button or not.
Then based on the X Y you get, make visible your set of buttons, be sure to make sure they're "topmost" or whatever.
I'm doing exactly what you suggest. The problem is that the MouseLeave and MouseEnter events don't take MouseEventArgs so I have to calculate the mouse position manually which doesn't seem to give the correct position. The docs say that Control.MousePosition is supposed to return the screen position of the Mouse which in my MouseLeave Event doesn't seem to be the case.


This *is* a windows application yes?
Yup, a C# Windows Application.
Dec 20 '07 #5

Plater
Expert 5K+
P: 7,872
[quote=Zaxxon21]I don't think that's correct: http://msdn2.microsoft.com/en-us/lib...eposition.aspx

"A Point that contains the coordinates of the mouse cursor relative to the upper-left corner of the screen."

[quote]


Just checked and verified I was correct.
Either we're talking about different things, or MS messed up their docmentation. In the mousemove event, the MouseArgs argument gives the X Y coordinates relative to the top left corner of the control that triggered the event.


I guess try the mouse move and not the mouseenter/exit?



Also: menustrips can be skinned to match things, what was the trouble with them?
Dec 20 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.