473,581 Members | 2,871 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get the point from MenuItem EventHandler?

I have a Forms.ContextMe nu with some Forms.MenuItem that has EventHandler for
the Click event.

The event handler function has the following signature:

private void OnMenuItemClick (object sender, System.EventArg s e)

I can not figure out how can the System.EventArg s e be helpful to me.

Can I get from the System.EventArg s e the Point where the mouse click for
opening the ContextMenu?
If I can use this System.EventArg s e to get this point, How?
------
Thanks
Sharon
Feb 20 '06 #1
9 2105
Hi Sharon,

Thanks for your post.

Yes, Click event does not provide parameter to get the mouse position,
however, we can still use Control.MousePo sition static property to get the
current mouse position in Click event handler.

Hope this helps!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Feb 21 '06 #2
Thanks Jeffrey,

But the ContextMenu is not derived from a Control so I can not use the
Control.MousePo sition.

Some more info:
The ContextMenu is of the DataGrid, and on one of the ContextMenu MenuItems
I want to know upon which row in the DataGrid the user clicked to open the
ContextMenu.
If I use the Control.MousePo sition on the MenuItem.Click event handler, I
get the point where the MenuItem was clicked which is not the point where the
user clicked to open the ContextMenu.

For now I solve the problem by saving the point on the OnMouseUp event and
working with this saved point on the MenuItem.Click event handler.
I was hoping to make it even more simple.

Can I?

P.S. : Did you see my latest post on "How to have DataGrid AutoScroll
without stealing the focus"
(http://msdn.microsoft.com/newsgroups...e-5fc250c11468) ?
Did you managed to reproduce the focus stealing?
------------
Thanks
Sharon
Feb 21 '06 #3
Hi Sharon,

Thanks for your feedback.

No, just as I stated in the original reply, Control.MousePo sition property
is a static property of Control class, so in ContextMenu, there is no need
to get any instance reference, we can just use Control.MousePo sition.X and
Control.MousePo sition.Y to get mouse x and y value.

Regarding "DataGrid AutoScroll" issue, I did not get any further feedback
in it. As I remember, the last message is that I sent the working sample
project to you. Have you got the sample project? Does it work on your side?

I suggest you post a new issue to discuss that question. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Feb 22 '06 #4
Hi Jeffrey,

As I mentioned, the ContextMenu is of the DataGrid, and on one of the
ContextMenu MenuItems I want to know upon which row in the DataGrid the user
clicked to open the ContextMenu.
If I use the Control.MousePo sition on the MenuItem.Click event handler, I
get the point where the MenuItem was clicked which is not the point where the
user clicked to open the ContextMenu. But I need to know the point where the
user clicked on the DataGrid before the ContextMenu was opened. But on
MenuItem.Click event handler the Control.MousePo sition gives the point where
the specific MenuItem was clicked which is different from the point I'm
looking for.
For now I solve the problem by saving the point on the OnMouseUp event and
working with this saved point on the MenuItem.Click event handler.

Regarding "DataGrid AutoScroll" issue, I did get your sample, and by looking
on the sample I can say this is exactly how I used it. So I extended the
sample to prove how the AutoScroll steals the focus.
Please look at my post at
http://msdn.microsoft.com/newsgroups...e-5fc250c11468
I there you can see my attachment reproducing the AutoScroll focus stealing
(using the Outlook Express).
----------
Thanks
Sharon
Feb 22 '06 #5
Hi ecydba,

Thanks for your post.

#1, sorry, it seems that I misunderstood your requirement.

#2, Before we go any further, can you first confirm if my sample work well
on your side?

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Feb 23 '06 #6
Hi Jeffrey,

Yes, your sample did scroll down when I clicked on the button.

You can take the sample I posted before and see exactly hoe the AutoScroll
steals the focus.
-------
Thanks
Sharon
Feb 23 '06 #7
Hi Sharon,

Thanks for your feedback.

Yes, I have got your sample project and reproduced out this problem. Then I
feel strange that why my sample works well while your sample does not work.
After doing some research I found that the problem lies in TabIndex
property.

In my sample, if we modify the Button's TabIndex property from 1 to 5, my
sample will not work either.
Also, in your sample, if you modify the NumericUpDown control's TabIndex
property from 3 to 1, and change the code statement below:

this.Invoke(new DoAutoScroll(th is.DoAutoScroll UI), null);
to
this.numericUpD own1.Invoke(new DoAutoScroll(th is.DoAutoScroll UI), null);

Then, the focus in the NumericUpDown will not lose.

Regarding this issue, I suggest you submit it as a bug request in the link
below:
http://lab.msdn.microsoft.com/ProductFeedback/

Our product team will receive your request and follow up with you.

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Feb 24 '06 #8
It takes a lot of changes in my real application code to implement the
workaround you suggested. We have another workaround that we discussed
earlier that works for now.
Furthermore, this workaround (and my current workaround) is good only when
the focus is stolen from a control within the same Form, but if the focus is
stolen from another Form, then it does not and the focus is steal stolen.

I opened a bug as you suggested, you can take a look at
http://lab.msdn.microsoft.com/Produc...ckId=FDBK46469

By the way; How did you find this weird workaround ???
------
Thanks
Sharon
Feb 27 '06 #9
Hi Sharon,

Thanks for your feedback.

Ok, let's wait the feedback from the product team, they may show us some
insight regarding this issue.

The the workaround, I just compare your reproduce project with my working
sample project. The only difference I found is the TabIndex, and further
test indicating that TabIndex will affect this behavior, so the imperfect
workaround comes out.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Feb 28 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1910
by: Lex | last post by:
As you may have seen in other posts I have a C# app that has custom shortcuts so I need to OwnerDraw my MenuItems. Thanx to vJ and Mick for the tips so far. I am almost there :-) My last (I hope) issue is aligning the menu text and shortcut text properly. I need it to line up as if there are two columns - 1 for the menu text and one for...
0
2760
by: Marcel | last post by:
Hi, the application I am writing has a MainMenu and a DataGrid (UltraGrid). Now I have to edit the text of each cell in this grid. So far so good. All works fine in editmode but if I press a key which is also a shortcut it doesn´t work and the menuitem-clickevent will be performed.
4
2292
by: Jesper | last post by:
Hi, When creating a popup menu I find it rather difficult to provide the eventhandler for the MenuItem with enough information. My actual problem is that I create a popup menu with a list of objects of which one, by clicking the item, must be assinged to another object. I use the same eventhandler for all the menuitems in the popup menu as...
0
1375
by: Claire | last post by:
When I run the following code through on the first round, my sub-menu (branched off mnuOpenPorts menuitem) shows a nice list of ports. When it gets run through on the 2nd pass, the sub menu indicates that it should be there but there's no items appearing in it. (ie a small indicator arrow is there showing there should be a sub menu but nothing...
4
3494
by: Claire | last post by:
Sorry Ive added this twice (sortof) but if I'd added an addendum to the first one then this would probably have been ignored. This problem affects a ContextMenu attached to a NotifyIcon object. I don't get the problem with context menus attached to list boxes etc. Ive also seen a noticeable slow down in speed when the menu attempts to hide...
2
1592
by: M Shafaat | last post by:
Hi, I want to develop an application with menus. I want to make only one event handler method which handles a whole group of menu items by firstly identifying which MenuItem sends the click event and then performing the appropriate action. But I don't find any way to retrieve any info telling me which specific MenuItem sends a click event at...
4
1600
by: Robin Tucker | last post by:
Hi there, I need to add a click handler to a derived menu item class. I am using the same handler to handle all of the items in the given menu, but need to derive a new menu item class in order to store a little extra information for each item. Previously, I was writing: MyMenu.MenuItems.Add ( "the text label", New...
4
3428
by: Eric Sabine | last post by:
I've simplified the code to the following. I'm just overlooking something very simple I'm sure. Dim mic() As MenuItem mic = New MenuItem(3) {} mic(0) = New MenuItem("a") mic(0).Index = 1 mic(1) = New MenuItem("b") mic(1).Index = 2
4
1812
by: Jeff Mason | last post by:
I have an application where I need to set certain menu items invisible based on a user privilege. We did a sinmlar thing in VB6 and used the menu item's tag property to assign an identifier to each menu entry, then used that identifier as an index into a collection populated at user login in order to determine the item's visibility. Now,...
0
7883
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7808
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...
0
8158
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7917
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...
0
6567
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...
0
3809
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...
0
3835
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2311
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 we have to send another system
1
1413
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.