HOW TO:設定由 Windows Form 控制項所顯示的文字

更新:2007 年 11 月

Windows Form 控制項通常會顯示與控制項主要功能相關的某些文字。例如,Button 控制項通常會顯示標題,以指示按一下按鈕時所執行的動作。對於所有的控制項,您可以使用 Text 屬性來設定或傳回文字。您可以藉由使用 Font 屬性以變更字型,也能使用設計工具設定文字。.

若要以程式設計的方式來設定由控制項所顯示的文字

  1. Text 屬性設定為字串。

    若要建立含有底線的便捷鍵,請在便捷鍵字母前面加上連字號 (&)。

  2. Font 屬性設定為 Font 型別的物件。

    Button1.Text = "Click here to save changes"
    Button1.Font = New Font("Arial", 10, FontStyle.Bold, GraphicsUnit.Point)
    
    button1.Text = "Click here to save changes";
    button1.Font = new Font("Arial", 10, FontStyle.Bold,
       GraphicsUnit.Point);
    
    button1.set_Text("Click here to save changes");
    button1.set_Font(new Font("Arial", 10, FontStyle.Bold,
       GraphicsUnit.Point));
    
    button1->Text = "Click here to save changes";
    button1->Font = new System::Drawing::Font("Arial",
       10, FontStyle::Bold, GraphicsUnit::Point);
    
    注意事項:

    您能夠使用逸出字元 (Escape Character) 顯示在使用者介面項目中通常會對它們做出不同解譯的特殊字元,例如功能表項目。例如,下列的程式碼行將功能表項目的文字設定為讀成「& Now For Something Completely Different」:

    MPMenuItem.Text = "&& Now For Something Completely Different"
    
    mpMenuItem.Text = "&& Now For Something Completely Different";
    
    mpMenuItem.set_Text("&& Now For Something Completely Different");
    
    mpMenuItem->Text = "&& Now For Something Completely Different";
    

請參閱

工作

HOW TO:建立 Windows Form 控制項的便捷鍵

HOW TO:回應 Windows Form Button 按一下動作

參考

Control.Text