Table of Contents

Class MenuItem

Namespace
System.Windows.Forms
Assembly
NetEx.Legacy.WinForms.dll

Represents an individual item that is displayed within a Menu or Menu.

public class MenuItem : Menu, IComponent, IDisposable
Inheritance
MenuItem
Implements
Inherited Members

Constructors

MenuItem()

Initializes a MenuItem with a blank caption.

public MenuItem()

MenuItem(string)

Initializes a new instance of the MenuItem class with a specified caption for the menu item.

public MenuItem(string text)

Parameters

text string

MenuItem(string, EventHandler)

Initializes a new instance of the class with a specified caption and event handler for the menu item.

public MenuItem(string text, EventHandler onClick)

Parameters

text string
onClick EventHandler

MenuItem(string, EventHandler, Shortcut)

Initializes a new instance of the class with a specified caption, event handler, and associated shorcut key for the menu item.

public MenuItem(string text, EventHandler onClick, Shortcut shortcut)

Parameters

text string
onClick EventHandler
shortcut Shortcut

MenuItem(string, MenuItem[])

Initializes a new instance of the class with a specified caption and an array of submenu items defined for the menu item.

public MenuItem(string text, MenuItem[] items)

Parameters

text string
items MenuItem[]

MenuItem(MenuMerge, int, Shortcut, string, EventHandler, EventHandler, EventHandler, MenuItem[])

Initializes a new instance of the class with a specified caption, defined event-handlers for the Click, Select and Popup events, a shortcut key, a merge type, and order specified for the menu item.

public MenuItem(MenuMerge mergeType, int mergeOrder, Shortcut shortcut, string text, EventHandler onClick, EventHandler onPopup, EventHandler onSelect, MenuItem[] items)

Parameters

mergeType MenuMerge
mergeOrder int
shortcut Shortcut
text string
onClick EventHandler
onPopup EventHandler
onSelect EventHandler
items MenuItem[]

Properties

BarBreak

Gets or sets a value indicating whether the item is placed on a new line (for a menu item added to a MainMenu object) or in a new column (for a submenu or menu displayed in a ContextMenu).

[Browsable(false)]
public bool BarBreak { get; set; }

Property Value

bool

Break

Gets or sets a value indicating whether the item is placed on a new line (for a menu item added to a MainMenu object) or in a new column (for a submenu or menu displayed in a ContextMenu).

[Browsable(false)]
public bool Break { get; set; }

Property Value

bool

Checked

Gets or sets a value indicating whether a checkmark appears beside the text of the menu item.

public bool Checked { get; set; }

Property Value

bool

DefaultItem

Gets or sets a value indicating whether the menu item is the default.

public bool DefaultItem { get; set; }

Property Value

bool

Enabled

Gets or sets a value indicating whether the menu item is enabled.

public bool Enabled { get; set; }

Property Value

bool

Index

Gets or sets the menu item's position in its parent menu.

[Browsable(false)]
public int Index { get; set; }

Property Value

int

IsParent

Gets a value indicating whether the menu item contains child menu items.

[Browsable(false)]
public override bool IsParent { get; }

Property Value

bool

MdiList

Gets or sets a value indicating whether the menu item will be populated with a list of the MDI child windows that are displayed within the associated form.

public bool MdiList { get; set; }

Property Value

bool

MenuID

Gets the Windows identifier for this menu item.

protected int MenuID { get; }

Property Value

int

MergeOrder

Gets or sets the relative position the menu item when its menu is merged with another.

public int MergeOrder { get; set; }

Property Value

int

MergeType

Gets or sets a value that indicates the behavior of this menu item when its menu is merged with another.

public MenuMerge MergeType { get; set; }

Property Value

MenuMerge

Mnemonic

Retrieves the hotkey mnemonic that is associated with this menu item. The mnemonic is the first character after an ampersand symbol in the menu's text that is not itself an ampersand symbol. If no such mnemonic is defined this will return zero.

[Browsable(false)]
public char Mnemonic { get; }

Property Value

char

OwnerDraw

Gets or sets a value indicating whether code that you provide draws the menu item or Windows draws the menu item.

public bool OwnerDraw { get; set; }

Property Value

bool

Parent

Gets the menu in which this menu item appears.

[Browsable(false)]
public Menu Parent { get; }

Property Value

Menu

RadioCheck

Gets or sets a value that indicates whether the menu item, if checked, displays a radio-button mark instead of a check mark.

public bool RadioCheck { get; set; }

Property Value

bool

Shortcut

Gets or sets the shortcut key associated with the menu item.

public Shortcut Shortcut { get; set; }

Property Value

Shortcut

ShowShortcut

Gets or sets a value that indicates whether the shortcut key that is associated with the menu item is displayed next to the menu item caption.

public bool ShowShortcut { get; set; }

Property Value

bool

Text

Gets or sets the text of the menu item.

public string Text { get; set; }

Property Value

string

Visible

Gets or sets a value that indicates whether the menu item is visible on its parent menu.

public bool Visible { get; set; }

Property Value

bool

Methods

CloneMenu()

Creates and returns an identical copy of this menu item.

public virtual MenuItem CloneMenu()

Returns

MenuItem

CloneMenu(MenuItem)

Creates a copy of the specified menu item.

protected void CloneMenu(MenuItem itemSrc)

Parameters

itemSrc MenuItem

Dispose(bool)

Disposes the MenuItem.

protected override void Dispose(bool disposing)

Parameters

disposing bool

MergeMenu()

Merges this menu item with another menu item and returns the resulting merged MenuItem.

public virtual MenuItem MergeMenu()

Returns

MenuItem

MergeMenu(MenuItem)

Merges another menu item with this menu item.

public void MergeMenu(MenuItem itemSrc)

Parameters

itemSrc MenuItem

OnClick(EventArgs)

Raises the Click event.

protected virtual void OnClick(EventArgs e)

Parameters

e EventArgs

OnDrawItem(DrawItemEventArgs)

Raises the DrawItem event.

protected virtual void OnDrawItem(DrawItemEventArgs e)

Parameters

e DrawItemEventArgs

OnInitMenuPopup(EventArgs)

protected virtual void OnInitMenuPopup(EventArgs e)

Parameters

e EventArgs

OnMeasureItem(MeasureItemEventArgs)

Raises the MeasureItem event.

protected virtual void OnMeasureItem(MeasureItemEventArgs e)

Parameters

e MeasureItemEventArgs

OnPopup(EventArgs)

Raises the Popup event.

protected virtual void OnPopup(EventArgs e)

Parameters

e EventArgs

OnSelect(EventArgs)

Raises the Select event.

protected virtual void OnSelect(EventArgs e)

Parameters

e EventArgs

PerformClick()

Generates a Click event for the MenuItem, simulating a click by a user.

public void PerformClick()

PerformSelect()

Raises the Select event for this menu item.

public virtual void PerformSelect()

ToString()

Returns a string representation for this control.

public override string ToString()

Returns

string

Events

Click

Occurs when the menu item is clicked or selected using a shortcut key defined for the menu item.

public event EventHandler Click

Event Type

EventHandler

DrawItem

Occurs when when the property of a menu item is set to true and a request is made to draw the menu item.

public event DrawItemEventHandler DrawItem

Event Type

DrawItemEventHandler

MeasureItem

Occurs when when the menu needs to know the size of a menu item before drawing it.

public event MeasureItemEventHandler MeasureItem

Event Type

MeasureItemEventHandler

Popup

Occurs before a menu item's list of menu items is displayed.

public event EventHandler Popup

Event Type

EventHandler

Select

Occurs when the user hovers their mouse over a menu item or selects it with the keyboard but has not activated it.

public event EventHandler Select

Event Type

EventHandler