473,511 Members | 14,981 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# Event Bubbling & Mouse Position Woes

3 New Member
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
5 4826
sigil
4 New Member
Why don't you just stick on a ContextMenuStrip when they right click?
Dec 19 '07 #2
Zaxxon21
3 New Member
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
7,872 Recognized Expert Expert
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
Zaxxon21
3 New Member
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
7,872 Recognized Expert Expert
[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

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

Similar topics

1
5519
by: DJ WIce | last post by:
Hi, I have a function on my page to zoom in (for people who have not very good eyes for example): var zoom_factor=100; function zoom(how) { var bodyStyle = document.body.style; zoom_factor...
4
14691
by: Jay | last post by:
Hi, How can I capture mouse position on Image? I found number of script capturing mouse position of the page. But I could not find anything based on image. What I want to find out is X Y...
6
30029
by: scot_nery | last post by:
I got this working in all browsers but FF/NS. It's not picking up the event to find the mouse position. In a perfect world, you mouse over the link and a mouse bubble pops up. Thanks for help....
4
1939
by: Wee Bubba | last post by:
the following event handler checks to see if any parent control has attached to the event 'SearchItemSelect'. i use it for event bubbling whenever one of my search items has been selected and at...
3
1293
by: Nathan Sokalski | last post by:
I have three LinkButtons in the HeaderTemplate of my DataList (I use them to let the user determine what to sort the list by). I am assuming that the event will be bubbled to the ItemCommand event...
7
2134
by: comzy | last post by:
I have created an event bubbling for my pager control which is used for implementing paging in data grid. Althoug it worked very fine in .NET 1.1 it is throwing the following error after i migrated...
1
5362
by: Sim | last post by:
Hello NG, I try to use drag and drop function between two list views. For this I found following code: ...
4
26472
by: vunet.us | last post by:
I have a DIV element. How can I find mouse position (top and left) inside of this DIV? <div onMouseMove="getPositions();" style="width:200px;height:100px"></div> function getPositions(ev){...
2
1658
by: alhalayqa | last post by:
hi, in MSIE, you can attach onclick event to both anchor and document objects. here is some code : document.onclick = function() {alert('document clicked ...'); } <a href= " " ...
0
7237
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7417
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5659
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3219
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3210
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1572
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
445
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.