The Label and LinkLabel Controls


The Label control is probably the most used control of them all. Look at any Windows application and you see a Label on just about every dialog you find. the Label is a simple control with one purpose only — to display text on the form.

the .NET Framework includes two label controls that present themselves in two distinct ways:

  • Label, the standard Windows label

  • LinkLabel, a label similar to the standard one (and derived from it), but that presents itself as an Internet link (a hyperlink)

Figure 14-9 shows one of each type of Label has been dragged to a form to illustrate the difference in appearance between the two.

image from book
Figure 14-9

And that's it for most uses of the Label control. Usually, you need to add no event handling code for a standard Label, although it does support events like all controls. In the case of the LinkLabel, however, some extra code is needed to allow users clicking it to go to the target of the LinkLabel.

You can set a surprising number of properties for the Label control. Most of these are derived from Control, but some are new. The following table lists the most common properties. Unless stated otherwise, the properties are common to both the Label and LinkLabel controls.

Name

Description

BorderStyle

Allows you to specify the style of the border around the Label. The default is no border.

FlatStyle

Determines how the control is displayed. Setting this property to Popup will make the control appear flat until the user moves the mouse pointer over the control. At that time, the control will appear raised.

Image

This property allows you to specify a single image (bitmap, icon, and so on) to be displayed in the label.

ImageAlign

Where in the Label the image is shown.

LinkArea

(LinkLabel only) The range in the text that should be displayed as a link.

LinkColor

(LinkLabel only) The color of the link.

Links

(LinkLabel only) It is possible for a LinkLabel to contain more than one link. This property allows you to find the link you want. The control keeps track of the links displayed in the text. Not available at design time.

LinkVisited

(LinkLabel only) Setting this to true means that the link is displayed in a different color if it has been clicked.

TextAlign

Where in the control the text is shown.

VisitedLinkColor

(LinkLabel only) The color of the LinkLabel after the user has clicked it.




Beginning Visual C# 2005
Beginning Visual C#supAND#174;/sup 2005
ISBN: B000N7ETVG
EAN: N/A
Year: 2005
Pages: 278

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net