* Merge winforms framework content to working branch (#14) * Breadcrumb / TOC / Move net5 to net folder (#15) * change path from net5 to net * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Add .net 5 winforms placeholder article (#16) * added some metadata and adjusted net5 placeholder * corrections * corrections * corrections * Test1 * Swapping landing page vs concept * fix links * Fix links * Fix desc
3.7 KiB
title, description, ms.date, dev_langs, helpviewer_keywords, ms.assetid
| title | description | ms.date | dev_langs | helpviewer_keywords | ms.assetid | |||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Set the Text Displayed by a Control | Learn how to set the text displayed by a Windows Forms control. Set or return the text by using the Text property, or change the font by using the Font property. | 08/20/2019 |
|
|
36b95bff-8780-479d-b86a-f1a0673653aa |
How to: Set the text displayed by a Windows Forms control
Windows Forms controls usually display some text that's related to the primary function of the control. For example, a xref:System.Windows.Forms.Button control usually displays a caption indicating what action will be performed if the button is clicked. For all controls, you can set or return the text by using the xref:System.Windows.Forms.Control.Text%2A property. You can change the font by using the xref:System.Windows.Forms.Control.Font%2A property.
You can also set the text by using the designer.
Programmatic
-
Set the xref:System.Windows.Forms.Control.Text%2A property to a string.
To create an underlined access key, includes an ampersand (&) before the letter that will be the access key.
-
Set the xref:System.Windows.Forms.Control.Font%2A property to an object of type xref:System.Drawing.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->Text = "Click here to save changes"; button1->Font = new System::Drawing::Font("Arial", 10, FontStyle::Bold, GraphicsUnit::Point);Note
You can use an escape character to display a special character in user-interface elements that would normally interpret them differently, such as menu items. For example, the following line of code sets the menu item's text to read "& Now For Something Completely Different":
MPMenuItem.Text = "&& Now For Something Completely Different"mpMenuItem.Text = "&& Now For Something Completely Different";mpMenuItem->Text = "&& Now For Something Completely Different";
Designer
-
In the Properties window in Visual Studio, set the Text property of the control to an appropriate string.
To create an underlined shortcut key, includes an ampersand (&) before the letter that will be the shortcut key.
-
In the Properties window, select the ellipsis button (
) next to the Font property.In the standard font dialog box, select the font, font style, size, effects (such as strikeout or underline), and script that you want.