MenuItem.Text 属性

定义

获取或设置一个值,通过该值指示菜单项标题。Gets or sets a value indicating the caption of the menu item.

public:
 property System::String ^ Text { System::String ^ get(); void set(System::String ^ value); };
public string Text { get; set; }
member this.Text : string with get, set
Public Property Text As String

属性值

菜单项的文本标题。The text caption of the menu item.

示例

下面的代码示例创建一个菜单项,设置标题,分配快捷键,使菜单项可见,并显示菜单项的快捷键显示方式。The following code 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. 该示例要求创建了MenuItemmenuItem1为的。The example requires that a MenuItem has been created that is named menuItem1.

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;
   }
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;
}
  
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

注解

为菜单项指定标题时,还可以通过在用作访问键的字符前放置 "&" 来指定访问密钥。When you specify a caption for your menu item, you can also specify an access key by placing an '&' before the character to be used as the access key. 例如,若要在 "File" 中将 "F" 指定为访问键,请将菜单项的标题指定为 "& 文件"。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.

如果将此属性设置-为 "",则会将菜单项显示为分隔符(水平线)而不是标准菜单项。Setting this property to "-" causes your menu item to be displayed as a separator (a horizontal line) rather than a standard menu item.

适用于

另请参阅