Text Property

MenuItem.Text Property

Gets or sets a value indicating the caption of the menu item.

[Visual Basic]
Public Property Text As String
[C#]
public string Text {get; set;}
[C++]
public: __property String* get_Text();
public: __property void set_Text(String*);
[JScript]
public function get Text() : String;
public function set Text(String);

Property Value

The text caption of the menu item.

Remarks

When you specify a caption for your menu item with the text parameter, you can also specify an access key by placing an '&' before the character to be used as the access key. For example, to specify the "F" in "File" as an access key, you would specify the caption for the menu item as "&File". You can use this feature to provide keyboard navigation for your menus.

Example

[Visual Basic, C#, C++] The following example creates a menu item, sets the caption, assigns a shortcut key, makes the menu item visible, and shows the shortcut key display for the menu item. The example assumes a MenuItem object has been created that is named menuItem1.

[Visual Basic] 
Public Sub SetupMyMenuItem()
    ' Set the caption for the menu item.
    menuItem1.Text = "&New"
    ' Assign a shortcut key.
    menuItem1.Shortcut = Shortcut.CtrlN
    ' Make the menu item visible.
    menuItem1.Visible = True
    ' Display the shortcut key combination.
    menuItem1.ShowShortcut = True
End Sub


[C#] 
public void SetupMyMenuItem()
{
   // Set the caption for the menu item.
   menuItem1.Text = "&New";
   // Assign a shortcut key.
   menuItem1.Shortcut = Shortcut.CtrlN;
   // Make the menu item visible.
   menuItem1.Visible = true;
   // Display the shortcut key combination.
   menuItem1.ShowShortcut = true;
}
  

[C++] 
public:
 void SetupMyMenuItem()
 {
    // Set the caption for the menu item.
    menuItem1->Text = S"&New";
    // Assign a shortcut key.
    menuItem1->Shortcut = Shortcut::CtrlN;
    // Make the menu item visible.
    menuItem1->Visible = true;
    // Display the shortcut key combination.
    menuItem1->ShowShortcut = true;
 }
   

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

MenuItem Class | MenuItem Members | System.Windows.Forms Namespace | Mnemonic

Show:
© 2016 Microsoft