ToggleButton Control

Description

Shows the selection state of an item.

Remarks

Use a ToggleButton to show whether an item is selected. If a ToggleButton is bound to a data source, the ToggleButton shows the current value of that data source as either Yes/No, True/False, On/Off, or some other choice of two settings. If the user selects the ToggleButton, the current setting is Yes, True, or On; if the user does not select the ToggleButton, the setting is No, False, or Off. If the ToggleButton is bound to a data source, changing the setting changes the value of that data source. A disabled ToggleButton shows a value, but is dimmed and does not allow changes from the user interface.

You can also use a ToggleButton inside a Frame to select one or more of a group of related items. For example, you can create an order form with a list of available items, with a ToggleButton preceding each item. The user can select a particular item by selecting the appropriate ToggleButton.

The default property of a ToggleButton is the Value property.

The default event of a ToggleButton is the Click event.

Properties

Accelerator property, Alignment property, AutoSize property, BackColor property, BackStyle property, BoundValue property, Caption property, ControlSource property, ControlTipText property, Enabled property, Font object, ForeColor property, Height, Width properties, HelpContextID property, LayoutEffect property, Left, Top properties, Locked property, MouseIcon property, MousePointer property, Name property, Object property, OldHeight, OldWidth properties, OldLeft, OldTop properties, Parent property, Picture property, PicturePosition property, SpecialEffect property, TabIndex property, TabStop property, Tag property, TripleState property, Value property, Visible property, WordWrap property.

Methods

Move method, SetFocus method, ZOrder method.

Events

AfterUpdate event, BeforeDragOver event, BeforeDropOrPaste event, BeforeUpdate event, Change event, Click event, DblClick event, Enter, Exit events, Error event, KeyDown, KeyUp events, KeyPress event, MouseDown, MouseUp events, MouseMove event.

Example

The following example uses the TripleState property to allow Null as a legal value of a CheckBox and a ToggleButton. The user controls the value of TripleState through ToggleButton2. The user can set the value of a CheckBox or ToggleButton based on the value of TripleState.

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

  • A CheckBox named CheckBox1.
  • A ToggleButton named ToggleButton1.
  • A ToggleButton named ToggleButton2.
    Private Sub UserForm_Initialize()
        CheckBox1.Caption = "Value is True"
        CheckBox1.Value = True
        CheckBox1.TripleState = False
        
        ToggleButton1.Caption = "Value is True"
        ToggleButton1.Value = True
        ToggleButton1.TripleState = False
    
        ToggleButton2.Value = False
        ToggleButton2.Caption = "Triple State Off"
    End Sub
    
    Private Sub ToggleButton2_Click()
        If ToggleButton2.Value = True Then
            ToggleButton2.Caption = "Triple State On"
            CheckBox1.TripleState = True
            ToggleButton1.TripleState = True
        Else
            ToggleButton2.Caption = "Triple State Off"
            CheckBox1.TripleState = False
            ToggleButton1.TripleState = False
        End If
    End Sub
    
    Private Sub CheckBox1_Change()
        If IsNull(CheckBox1.Value) Then
            CheckBox1.Caption = "Value is Null"
        ElseIf CheckBox1.Value = False Then
            CheckBox1.Caption = "Value is False"
        ElseIf CheckBox1.Value = True Then
            CheckBox1.Caption = "Value is True"
        End If
    End Sub
    
    Private Sub ToggleButton1_Change()
        If IsNull(ToggleButton1.Value) Then
            ToggleButton1.Caption = "Value is Null"
        ElseIf ToggleButton1.Value = False Then
            ToggleButton1.Caption = "Value is False"
        ElseIf ToggleButton1.Value = True Then
            ToggleButton1.Caption = "Value is True"
        End If
    End Sub