A Label control, of the class System.Windows.Forms.Label, displays read-only text on a form. Text controls that provide read/write capability, such as the TextBox and RichTextBox, are described in Chapter 12.

Labels serve several different functions. At the most basic level, they display text on the client area of a form, such as titles, paragraphs, or captions for other controls. The text displayed by a Label is contained in its Text property. The Text property can be either hardcoded (set at design time) or dynamic (set programmatically at runtime).

Several examples presented in Chapter 7 dynamically control the size of a control (a button was used in the examples), based on the Text property of the control and the size of the font for that control. The Label control eases this chore with the AutoSize property. When set to true, the control is automatically resized to display the entire contents of the Text property.

In addition to the properties just mentioned, the Label control has many other properties, the most commonly used of which are listed in Table 11-1.

Table 11-1. Label properties


Value type




Read/write. Value indicating that the label will automatically resize to display the entire Text property. Default is false. Using both PreferredWidth and PreferredHeight yields the same label size as AutoSize set to true.



Read/write. The background image displayed on the label.


BorderStyle ...

Get Programming .NET Windows Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.