473,625 Members | 2,770 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 2108
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
1914
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 the shortcut text. The menu text is left justified in col 1 and shortcur text is left justified...
0
2766
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
2295
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 the objects listed in the popup menu is of arbitrary length. To correlate the 'sender' menuitem in...
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 pops up) When I step through the code, I have 5 items in Comports. After adding all the sub menu...
4
3501
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 after the problem occurs. When I build a dynamic submenu on the first time round, it shows a nice...
2
1594
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 the moment. The sender and e parameters seem to carry some very general information, not from a...
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 EventHandler(AddressOf
4
3434
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
1818
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, for some reason there's no tag property for .NET MenuItems, so I'm looking for some way to...
0
8253
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8692
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8354
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
8497
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7182
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
6116
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
5570
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
4089
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...
1
2621
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

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.