Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show checkbox for Context MenuStrip or Context Menu of a button

I am designing a logging feature in which User can select which event he wants to log. On clicking button, I am showing such type of menu: Context Menu on Button click

User can select multiple Events so I need to show "Check Mark" infront of the selected option when user clicks on it.

I am unable to find any options like "Checked" or "CheckOnClick" as mentioned in this question.

I tried with ContextMenu and ContextMenuStrips but couldn't achieve Checkboxes. Any Suggestions??

like image 716
Swanand Avatar asked Sep 13 '12 06:09

Swanand


People also ask

How do I show context menu?

Typically, a ContextMenu is displayed when the user clicks the right mouse button on a control or area of the form that the ContextMenu is bound to. You can use this method to manually display the shortcut menu at a specific location and bind it with a specific control.

How can you attach context menu to a control?

In the Link to Command designer, change the following command properties. Select ContextMenu from the Create a new command listbox. This will create a command with a submenu which can be used as a context menu. Select OK, in the Link to Command dialog box.

What is a ContextMenuStrip?

The ContextMenuStrip control represents a shortcut menu that pops up over controls, usually when you right click them. They appear in context of some specific controls, so are called context menus. For example, Cut, Copy or Paste options.


2 Answers

Don't see any of your code so I don't know how you create this menu. But in the most general terms, here is how you access the Checked property.

((ToolStripMenuItem)contextMenuStrip.Items[0]).Checked = true; //false;
((ToolStripMenuItem)contextMenuStrip.Items[1]).Checked = true; //false;
((ToolStripMenuItem)contextMenuStrip.Items[2]).Checked = true; //false;

You can assign them as either true or false. If you have named your ToolStripItems, then you can access them directly rather than going to the Items array.

contextMenuStrip.event1.Checked = true; //false;

As you can see, I am using a ContextMenuStrip.

like image 92
Michael Mankus Avatar answered Oct 13 '22 09:10

Michael Mankus


Change the property CheckOnClick to True

enter image description here

like image 20
WeSam Abdallah Avatar answered Oct 13 '22 09:10

WeSam Abdallah