Label Control

Description

Displays descriptive text.

Remarks

A Label control on a form displays descriptive text such as titles, captions, pictures, or brief instructions. For example, labels for an address book might include a Label for a name, street, or city. A Label doesn't display values from data sources or expressions; it is always unbound and doesn't change as you move from record to record.

The default property for a Label is the Caption property.

The default event for a Label is the Click event.

Properties

Accelerator property, AutoSize property, BackColor property, BackStyle property, BorderColor property, BorderStyle property, Caption property, ControlTipText property, Enabled property, Font object, ForeColor property, Height, Width properties, LayoutEffect property, Left, Top properties, MouseIcon property, MousePointer property, Name property, Object property, OldHeight, OldWidth properties, OldLeft, OldTop properties, Parent property, Picture property, PicturePosition property, SpecialEffect property, TabIndex property, Tag property, TextAlign property, Visible property, WordWrap property.

Methods

Move method, ZOrder method.

Events

BeforeDragOver event, BeforeDropOrPaste event, Click event, DblClick event, Error event, MouseDown, MouseUp events, MouseMove event.

Example

The following example uses the Zoom event to evaluate the new value of the Zoom property and adds scroll bars to the form when appropriate. The example uses a Label to display the current value. The user specifies the size for the form by using the SpinButton and then clicks the CommandButton to set the value in the Zoom property.

To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains:

  • A Label named Label1.
  • A SpinButton named SpinButton1.
  • A CommandButton named CommandButton1.
  • Other controls placed near the edges of the form.
    Private Sub CommandButton1_Click()
        Zoom = SpinButton1.Value
    End Sub
    
    Private Sub SpinButton1_SpinDown()
        Label1.Caption = SpinButton1.Value
    End Sub
    
    Private Sub SpinButton1_SpinUp()
        Label1.Caption = SpinButton1.Value
    End Sub
    
    Private Sub UserForm_Initialize()
        SpinButton1.Min = 10
        SpinButton1.Max = 400
        SpinButton1.Value = 100
        Label1.Caption = SpinButton1.Value
        
        CommandButton1.Caption = "Zoom it!"
    End Sub
    
    Private Sub UserForm_Zoom(Percent As Integer)
        Dim MyResult As Double
        
        If Percent > 99 Then
            ScrollBars = fmScrollBarsBoth
            ScrollLeft = 0
            ScrollTop = 0
        
            MyResult = Width * Percent / 100
            ScrollWidth = MyResult
        
            MyResult = Height * Percent / 100
            ScrollHeight = MyResult
        Else
            ScrollBars = fmScrollBarsNone
            ScrollLeft = 0
            ScrollTop = 0
        End If
    End Sub