tags:

views:

1972

answers:

4

Hello! I have a series of checkboxes on a form. I want to be able to select these from a context menu as well as the form itself. The context menu is linked to the system tray icon of the application.

My question is, is it possible to link the context menu to these checkboxes? Or even possible to add checkboxes to the context menu? Or even a combination?!

+4  A: 

The menu items have a Checked property (MenuItem.Checked, ToolStripMenuItem.Checked) that you can use for this purpose.

Regarding the possibility to link the context menu items to the check boxes, if you use a ContextMenuStrip and set CheckOnClick property to true, you can hook up the CheckedChanged events to the same event handler for the ToolStripMenuItem and CheckBox controls that should be "linked", and inside that event handler make sure to synchronize the Checked property of the controls and perform any other needed actions.

Fredrik Mörk
A: 

Well, a menu item has the "Checked" property, which can make it behave like a checkbox. When you click a menu item, you can programmatically toggle the state of the corresponding checkbox on your form.

You can also use the Opening event of the context menu to set the Checked state of the menu items based on the checked state of the checkboxes.

Dmitry Brant
A: 

You can host standard as well as custom controls by wrapping them in a ToolStripControlHost

http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstripcontrolhost.aspx

OG
A: 

//Create the combo box object and set its properties cmbFunctionArea = new ComboBox(); cmbFunctionArea.Cursor = System.Windows.Forms.Cursors.Arrow; cmbFunctionArea.DropDownStyle=System.Windows.Forms.ComboBoxStyle.DropDownList; cmbFunctionArea.Dock = DockStyle.Fill; //Event that will be fired when selected index in the combo box is changed cmbFunctionArea.SelectionChangeCommitted += new EventHandlercmbFunctionArea_SelectedIndexChanged);

shawn