Home
C#.WinForms
Text Property
Updated Nov 16, 2023
Dot Net Perls
Text. This is a property—it is available on Windows Forms controls. You can get and set this property to change the string that stores the text for the control.
Text notes. Controls implement Text differently. On a Form, the Text will be rendered as the window's title. But other controls will render Text in other places.
In this program, we use a TextBox as well the default Form. We assign the Text property of the enclosing Form (this) and the TextBox instance (textBox1).
Form
using System; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // Form has a Text property. this.Text = "Dot Net Perls"; // TextBox has a Text property. textBox1.Text = "Thanks"; } } }
Results. You can see the results of this program in the screenshot. The title bar text of the window has its text changed to "Dot Net Perls". And the TextBox contains the string "Thanks".
Tip The Text property can be assigned to a string variable reference, or a string literal.
A summary. Knowing how to use the Text property on a Form is confusing because we often don't think of the title bar as text. Other controls implement it a different way.
Dot Net Perls is a collection of pages with code examples, which are updated to stay current. Programming is an art, and it can be learned from examples.
Donate to this site to help offset the costs of running the server. Sites like this will cease to exist if there is no financial support for them.
Sam Allen is passionate about computer languages, and he maintains 100% of the material available on this website. He hopes it makes the world a nicer place.
This page was last updated on Nov 16, 2023 (edit).
Home
Changes
© 2007-2025 Sam Allen