How to find Context menu was shown and not to handle click events

I got a quick question,

I am developing a custom chart control. The chart control let users to draw lines or drop rectangle (could be anything). This start draw/ drop options are set to controls mouse down, left button click and mouse down right click is set to show context menu.

My problem is, if user decide not to select anything and come out from context menu while it is shown they should left click on control as right click will show the menu again. But at the moment context menu is diapering and rest of the left click also executed. How can I verify context menu was shown on left click and user wants to come out from context menu and not to execute start draw/ drop logic.

Additional Info: I am working on C# project, I tried to capture context menu closed event but it triggers and closes itself before it comes to controls mouse down event and I can not verify was context menu was shown before to avoid going through rest of the left mouse button down event logic.

Any help is greatly appreciated in advance.

-------------Problems Reply------------

Here's a simple solution.

Suppose you have a ListBox control on your form which has a ContextMenu associated with it. now we wanna add a list item to the control each time it is clicked:

private void listBox1_MouseClick(object sender, MouseEventArgs e)
listBox1.Items.Add("new item added - " + DateTime.Now.ToLongTimeString());

Now define a bool variable at your form level called menuClosed like so:

private bool menuClosed = false;

Now capture the context menu's Closed event like so and flip the flag:

private void contextMenuStrip1_Closed(object sender, ToolStripDropDownClosedEventArgs e)
menuClosed = true;

Now update the code that adds an item to the list box control like the following:

private void listBox1_MouseClick(object sender, MouseEventArgs e)
if (!menuClosed)
listBox1.Items.Add("new item added - " + DateTime.Now.ToLongTimeString());

I'm just setting the bool variable to true when the context menu is closed, then i check for the bool flag to see if an item should be added to the list. you can use this kinda same mechanism to determine a specific command should be executed or not. hope it helps.

Category:c# Views:0 Time:2011-08-08

Related post

  • How do I handle click events in a data bound menu in WPF 2008-12-01

    I've got a MenuItem whos ItemsSource is databound to a simple list of strings, its showing correctly, but I'm struggling to see how I can handle click events for them! Here's a simple app that demonstrates it: <Window x:Class="WPFDataBoundMenu.Win

  • Blackberry trackball click, instead of responding to event, context menu is shown why? 2009-08-17

    I'm running into the following scenario on some devices: when the use clicks on field and expects an response, instead of properly responding to that click event, the device shows the context menu at the bottom center of the screen. navigationUnclick

  • Windows Explorer Context Menu Integration, get file that was right clicked on 2010-06-11

    I've already figured out how to add a menu item to the right click context menu of the windows explorer using the registry. I currently have it set to launch my application when my menu item is clicked. However, I want to know if there is a way to kn

  • Rightclick Context Menu Position is getting Changed on right click of different objects 2010-11-19

    I have created a ShellExtension which add "Start N Application" to the windows right click menu. But the problem is that , the position of the context meny is not fixed. When I rightclick on a drive , it shows up in 3 rd position , or if I rightclick

  • Browser Context Menu customization? 2009-12-23

    Is there a way to override the "undo" and "select all" in right click context menu of the browser over textarea? Thank you. --------------Solutions------------- You cannot edit the browser's built-in context menu, but you can disable it and replace i

  • Windows Shell Context Menu option 2009-08-24

    I need to create an option for all files that would run a batch file located in Windows directory or any other directory. The batch file will basically delete the files and will also delete it from another server. I have the batch file wworking just

  • GWT: context menu in RichTextArea 2009-10-23

    I'm using a RichTextArea in a GWT app. I want to add a context menu to my RichTextArea: public class MyRichTextArea extends RichTextArea implements HasContextMenuHandlers { public HandlerRegistration addContextMenuHandler(ContextMenuHandler h) { retu

  • Creating context menu for win32 API 2010-02-22

    I am trying to create context menu for win32 application using case WM_RBUTTONDOWN: { HMENU hPopupMenu = CreatePopupMenu(); InsertMenu(hPopupMenu, 0, MF_BYPOSITION | MF_STRING, ID_CLOSE, (LPCWSTR)"Exit"); InsertMenu(hPopupMenu, 0, MF_BYPOSITION | MF_

  • Showing windows (file/directory) context menu in c# winforms application 2010-04-06

    I'm trying to display standard file/directory context menu in WinForms application - I'd like to enable the user to do things with files in my application as he could in Explorer. There should be two options popup the context menu with some system ca

  • Custom cursor and customized context menu in Flex 2010-06-24

    My Flex 3 application uses a custom cursor and has to show a customized context menu when the user performs a right click. The problem is the customized menu is shown only when the default arrow cursor is shown. When I change it to the custom cursor,

  • Android custom context menu 2011-01-09

    I would like to create a context menu (long press on a textview) that will show a list of options. Difference from regular context menu will be, that the use is different: user will long click on the textview, menu will popup, user will not release f

  • How to create a Context Menu on a MapView? 2011-01-14

    I would like to have a Context Menu on my MapView and let the user choose between a map or a satellite photo in the background. I have tried to create a Context Menu by following Creating Menus but it doesn't work for me. The application works but no

  • Context menu within a menu item in ExtJS 2011-03-10

    I have a Menu that contains a TreePanel. The users need to be able to interact with a the TreePanel's nodes using a context menu. I'm showing the context menu from a function attached to the TreePanel's contextmenu event. This works except: Without a

  • how to show icons in context menu in android 2011-06-16

    I am newbie to android. I have a button on my app. When i click that it should display context Menu . But I know we can not show icons in context Menu. But I have seen few Apps having icons in their context menu as shown in the link. http://pavansdro

  • How to show EditText's context menu on long press when it's inside a gallery? 2011-08-13

    my program is based on Google's Hello Gallery example: Instead of using images, I create a bunch of EditTexts in the constructor. My question is now: When I long click on an EditTe

  • Design advice concerning creation of context menu 2011-10-21

    If someone have an HTC device and go to the SMS messages and tap on some of the messages in the thread then an context menu is shown. I have an list and I do not know what is the right thing to put the context menu to be shown on longpress or just on

  • Use javascript to prevent context menu on CTRL+Leftclick 2011-11-25

    I am trying to allow my CMS users to click certain controls with ALT+CTRL both pressed, but this results in the context menu being shown, because CTRL+Leftclick simulates a rightclick, at least here on Mac OSX (which is the primary OS of my client).

  • Visual studio add in context menu does not receive events 2012-02-11

    I'm experimenting with a visual studio addon and have come across very odd behaviour. I'm adding a right click context menu item and I'm not getting the events to fire unless I put a breakpoint in the OnConnect method and wait a little while. I'm doi

  • Get click position on a canvas in a handler of a context-menu 2012-04-11

    I have an Eclipse RCP-Application, where a menu-contribution is registered, so that a context-menu will automatically be shown, when the user right-clicks on a special canvas in a defined view. Now in some handlers I want to be able, to get the mouse

Copyright (C), All Rights Reserved.

processed in 0.072 (s). 11 q(s)