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

How to get the point from MenuItem EventHandler?

P: n/a
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
Share this Question
Share on Google+
9 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.