語言

MenuItem.Text 屬性

定義

會取得或設定一個值,指示菜單項目的說明文字。

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

屬性值

菜單上的文字說明。

範例

以下程式碼範例會建立選單項目、設定說明文字、指派快捷鍵、讓選單項目可見,並顯示該選單項目的快捷鍵顯示。 該範例要求已建立一個 MenuItem 名為 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

備註

當你為菜單項目指定說明文字時,也可以在要用的字元前加上「&」來指定存取鍵。 例如,若要指定「File」中的「F」作為存取鍵,你可以將選單項目的說明文字指定為「&File」。 你可以利用這個功能來提供選單的鍵盤導航。

將此屬性設為「-」後,選單項目會以分隔符(水平線)顯示,而非標準選單項目。

適用於

另請參閱