Label


The Label control displays some read-only text. Note that you cannot even select the text at runtime so, for example, you cannot copy it to the clipboard. If you want to allow the user to select and copy text, but not modify it, use a TextBox with the ReadOnly property set to True.

The Label control can display an image in addition to text. To display an image, either set the control’s Image property to the image or set the control’s ImageList and ImageIndex properties. Use the ImageAlign and TextAlign properties to determine where the image and text are positioned within the control.

If you set the Label control’s AutoSize property to True (the default), then the control resizes itself to fit its text. This can be particularly useful for controls that contain text that changes at runtime because it ensures that the control is always big enough to hold the text. Note that the control does not automatically make itself big enough to display any image it contains.

The Label control automatically breaks lines that contain embedded carriage returns. The following code makes a label display text on four lines:

  lblInstructions.Text = "Print this message and either:" & vbCrLf & _     "    - Mail it to the recipient" & vbCrLf & _     "    - Fax it to the recipient" & vbCrLf & _     "    - Throw it away" 

Text that contains carriage returns confuses the control’s AutoSize capabilities, however, so you should not use AutoSize with multiline text.

The Label control also automatically wraps to a new line if the text it contains is too long to fit within the control’s width.




Visual Basic 2005 with  .NET 3.0 Programmer's Reference
Visual Basic 2005 with .NET 3.0 Programmer's Reference
ISBN: 470137053
EAN: N/A
Year: 2007
Pages: 417

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