Name
Label
Synopsis
This Control
provides a simple, non-editable text
label.
The control has the ability to AutoSize
to the
content, although care should be taken to ensure that the layout
engine can cope with this neatly. If you set the
UseMnemonic
property to true
,
you can use Alt key shortcuts. The control strips out the first
&, underlines the subsequent character, and ensures that the
focus is set to the next element in the tab order when the Alt key
combination is pressed. The label itself cannot receive the focus.
In addition to the Text
, you can add an
Image
or an item from an
ImageList
(the one at a particular
ImageIndex
).
Alternatively, you can set the FlatStyle
to
System
, and fall back on the standard OS
rendering, perhaps for XP theme support. You lose the image support,
however.
public class Label : Control { // Public Constructors public Label(); // Public Instance Properties public virtual bool AutoSize{set; get; } public override Image BackgroundImage{set; get; } // overrides Control public virtual BorderStyle BorderStyle{set; get; } public FlatStyle FlatStyle{set; get; } public Image Image{set; get; } public ContentAlignment ImageAlign{set; get; } public int ImageIndex{set; get; } public ImageList ImageList{set; get; } public ImeMode ImeMode{set; get; } // overrides Control public virtual int PreferredHeight{get; } public virtual int PreferredWidth{get; } public bool TabStop{set; get; } // overrides Control public virtual ContentAlignment TextAlign{set; get; } public ...
Get .NET Windows Forms in a Nutshell 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.