Alignment Property

Applies To

CheckBox control, OptionButton control, ToggleButton control.

Description

Specifies the position of a control relative to its caption.

Syntax

object.Alignment [= fmAlignment]

The Alignment property syntax has these parts:

Part

Description

object

Required. A valid object.

fmAlignment

Optional. Caption position.


Settings

The settings for fmAlignment are:

Constant

Value

Description

fmAlignmentLeft

0

Places the caption to the left of the control.

fmAlignmentRight

1

Places the caption to the right of the control (default).


Remarks

The caption text for a control is left-aligned.

Note Although the Alignment property exists on the ToggleButton, the property is disabled. You cannot set or return a value for this property on the ToggleButton.

Example

The following example demonstrates the Alignment property used with several OptionButton controls. In this example, the user can change the alignment by clicking a ToggleButton.

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

  • Two OptionButton controls named OptionButton1 and OptionButton2.
  • A ToggleButton named ToggleButton1.
    Private Sub UserForm_Initialize()
        OptionButton1.Alignment = fmAlignmentLeft
        OptionButton2.Alignment = fmAlignmentLeft
    
        OptionButton1.Caption = "Alignment with AutoSize"
        OptionButton2.Caption = "Choice 2"
        OptionButton1.AutoSize = True
        OptionButton2.AutoSize = True
        
        ToggleButton1.Caption = "Left Align"
        ToggleButton1.WordWrap = True
        ToggleButton1.Value = True
    End Sub
    
    Private Sub ToggleButton1_Click()
        If ToggleButton1.Value = True Then
            ToggleButton1.Caption = "Left Align"
            OptionButton1.Alignment = fmAlignmentLeft
            OptionButton2.Alignment = fmAlignmentLeft
        Else
            ToggleButton1.Caption = "Right Align"
            OptionButton1.Alignment = fmAlignmentRight
            OptionButton2.Alignment = fmAlignmentRight
        End If
    End Sub