Adding Check Marks to Menu Items

You can display check marks next to any menu item except a top-level menu item. This is useful when you want to indicate to the user that a menu option is selected or enabled. You can display a check mark beside a menu item by setting the Checked property to True, as shown here:

OptionToolStripMenuItem.Checked = True // C#

optionToolStripMenuItem.Checked = true;

Alternatively, you can define whether the menu item is selected by setting the CheckState property to Checked, as shown here:

OptionToolStripMenuItem.CheckState = CheckState.Checked // C#

optionToolStripMenuItem.CheckState = CheckState.Checked;

The Checked property is a Boolean property that returns whether an item is checked. If the item is checked, the Checked property returns True. If the item is in any other state, the Checked property returns False. The CheckState property on the other hand, indicates the actual state of the menu item and will return either CheckState.Checked, CheckState.UnChecked, or Checkstate.Indeterminate.

If you want a menu item to appear checked when the user clicks the item, you can set the CheckOnClick property to True. This will cause the check mark on the menu item to toggle between checked and unchecked each time the user clicks the menu item. You can programmatically change the check state or determine if the menu item is checked using the ToolStripMenuItem.CheckState or ToolStripMenuItem.Checked properties.

Was this article helpful?

0 0

Post a comment