Label
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
|
Property |
Value type |
Description |
|---|---|---|
|
AutoSize |
Boolean |
Read/write. Value indicating that the label will automatically resize
to display the entire Text property. Default is
|
|
BackgroundImage |
Image |
Read/write. The background image displayed on the label. |
|
BorderStyle |
BorderStyle ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access