473,503 Members | 1,647 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.ContextMenu 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.EventArgs e)

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

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

Thanks for your post.

Yes, Click event does not provide parameter to get the mouse position,
however, we can still use Control.MousePosition 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.MousePosition.

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.MousePosition 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.MousePosition 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.MousePosition.X and
Control.MousePosition.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.MousePosition 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.MousePosition 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(this.DoAutoScrollUI), null);
to
this.numericUpDown1.Invoke(new DoAutoScroll(this.DoAutoScrollUI), 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
1900
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...
0
2745
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...
4
2285
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...
0
1369
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...
4
3484
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...
2
1590
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...
4
1592
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...
4
3419
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 ...
4
1803
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...
0
7201
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
7083
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...
0
7278
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,...
0
7456
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
5578
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,...
1
5011
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...
0
4672
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...
0
3166
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...
1
734
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.