473,699 Members | 2,203 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(C ontrol.MousePos ition). 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 4846
sigil
4 New Member
Why don't you just stick on a ContextMenuStri p when they right click?
Dec 19 '07 #2
Zaxxon21
3 New Member
Why don't you just stick on a ContextMenuStri p 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.MousePo sition 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
5551
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 = (how)?100:110;
4
14723
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 coordinates of mouse position. based on left of the top of my image is 0 0 (X Y coordinates) otherwise, I need to find out position of my image so I can calculate.
6
30041
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. scot
4
1952
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 the moment i am calling this from a repeater's ItemCommand event handler: protected void OnSearchItemSelect(EventArgs e) { if (SearchItemSelect != null) { SearchItemSelect (this, e);
3
1306
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 (since that is the default and I did not supply a CommandName). However, I need to determine which of the three LinkButtons triggered the event. How can I do this? Thanks. -- Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/
7
2142
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 it to .NET 2.0 The peculiar thing abou that is it is throwing error only in IE 6.0 and it works fine in netscape, firefox, opera even after converting it to ..NET 2.0 Can anyone tell me whether anything has changed in event bubbling format...
1
5372
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: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchimpdragdrop.asp It works fine, but I have another problem. I want to create functionality like a Windows Explorer. This means, if I select some items from list view No 1 and drag&drop this to the list view No 2, then I want to mark automatically
4
26486
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
1666
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= " " onclick="clickHandler"></a>
0
8623
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8935
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7773
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6540
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5879
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4389
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2015
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.