C# Add Checkbox To WinForms Context Menu

前端 未结 4 2032
一整个雨季
一整个雨季 2021-01-02 08:21

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

相关标签:
4条回答
  • 2021-01-02 08:38

    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.

    0 讨论(0)
  • 2021-01-02 08:43

    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

    0 讨论(0)
  • 2021-01-02 08:52

    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.

    0 讨论(0)
  • 2021-01-02 09:01
      //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);
    
    0 讨论(0)
提交回复
热议问题