logo

Toolbox Checkbox

Checkboxes in an InForm application enable users to select binary settings, such as true/false, yes/no, or enabled/disabled options.

Checkbox control

Create a new Checkbox control by clicking the Checkbox icon ToolBox checkbox in the Toolbox. The newly created control will be displayed in the preview window; allowing you to move it around to meet your design requirements. Edit the Checkbox properties as necessary.

5) Checkbox Properties:

ToolBox

Checkbox examples: Preview window.

ToolBox

Note: Checkbox properties will reflect the highlighted control selected in the preview window, enabling you to customize it as needed.

Checkboxes enable users to select binary settings, such as true/false, yes/no, or enabled/disabled options.
The user is presented with a box that is either empty or checked, accompanied by a label indicating the setting being edited.

At design time, you can set the Value property to True or False to preselect the checkbox with a checkmark. During runtime, user manipulation triggers the ValueChanged event, allowing you to read the .Value property, which returns either True or False.

UserChoice%% = Control(ControlID).Value

Utilize the SetCaption method to define a hot-key shortcut for your CheckBox control by placing an ampersand character (&) before the letter you want to assign as a shortcut (Alt+letter).

Checkbox examples - refer to the above image.

Specification: Let the checkbox examples have the following design specification:

  1. Add four checkboxes labeled Lettuce, Tomato, Mustard, and Ham, as shown above.
  2. By default, all options are unchecked except for Lettuce.
  3. Include two buttons one to select all the checkboxes and the other to reset all checkboxes.
  4. During runtime, upon loading the application, disable the Ham option and add the tooltip 'No ham today'

Implimenation: The following provide solutions for the above:

Basic file CheckboxTest.bas


': This program uses
': InForm - GUI library for QB64 - v1.5
': Fellippe Heitor, 2016-2024 - fellippe@qb64.org - @fellippeheitor
': https://github.com/FellippeHeitor/InForm
'-----------------------------------------------------------
Option _Explicit '                 <---

': Controls' IDs: ------------------------------------------------------------------
Dim Shared CheckboxTest As Long
Dim Shared LetuceCB As Long
Dim Shared TomatoCB As Long
Dim Shared MustardCB As Long
Dim Shared SandwitchContentsLB As Long
Dim Shared HamCB As Long
Dim Shared SelectAllBT As Long
Dim Shared ResetBT As Long

': External modules: ---------------------------------------------------------------
'$INCLUDE:'InForm\InForm.bi'
'$INCLUDE:'InForm\xp.uitheme'
'$INCLUDE:'CheckboxTest.frm'

': Event procedures: ---------------------------------------------------------------
Sub __UI_BeforeInit

End Sub

Sub __UI_OnLoad
    ToolTip(HamCB) = "Sorry no ham today" '     <---
    Control(HamCB).Disabled = TRUE '            <---

End Sub

Sub __UI_BeforeUpdateDisplay
    'This event occurs at approximately 60 frames per second.
    'You can change the update frequency by calling SetFrameRate DesiredRate%

End Sub

Sub __UI_BeforeUnload
    'If you set __UI_UnloadSignal = False here you can
    'cancel the user's request to close.

End Sub

Sub __UI_Click (id As Long)
    Select Case id
        Case CheckboxTest

        Case LetuceCB

        Case TomatoCB

        Case MustardCB

        Case SandwitchContentsLB

        Case HamCB

        Case SelectAllBT
            Control(LetuceCB).Value = TRUE '  <---
            Control(TomatoCB).Value = TRUE '  <---
            Control(MustardCB).Value = TRUE ' <---
            Control(HamCB).Value = TRUE '     <---
        Case ResetBT
            Control(LetuceCB).Value = FALSE '  <---
            Control(TomatoCB).Value = FALSE '  <---
            Control(MustardCB).Value = FALSE ' <---
            Control(HamCB).Value = FALSE '     <---

    End Select
End Sub

Sub __UI_MouseEnter (id As Long)
    Select Case id
        Case CheckboxTest

        Case LetuceCB

        Case TomatoCB

        Case MustardCB

        Case SandwitchContentsLB

        Case HamCB

        Case SelectAllBT

        Case ResetBT

    End Select
End Sub

Sub __UI_MouseLeave (id As Long)
    Select Case id
        Case CheckboxTest

        Case LetuceCB

        Case TomatoCB

        Case MustardCB

        Case SandwitchContentsLB

        Case HamCB

        Case SelectAllBT

        Case ResetBT

    End Select
End Sub

Sub __UI_FocusIn (id As Long)
    Select Case id
        Case LetuceCB

        Case TomatoCB

        Case MustardCB

        Case HamCB

        Case SelectAllBT

        Case ResetBT

    End Select
End Sub

Sub __UI_FocusOut (id As Long)
    'This event occurs right before a control loses focus.
    'To prevent a control from losing focus, set __UI_KeepFocus = True below.
    Select Case id
        Case LetuceCB

        Case TomatoCB

        Case MustardCB

        Case HamCB

        Case SelectAllBT

        Case ResetBT

    End Select
End Sub

Sub __UI_MouseDown (id As Long)
    Select Case id
        Case CheckboxTest

        Case LetuceCB

        Case TomatoCB

        Case MustardCB

        Case SandwitchContentsLB

        Case HamCB

        Case SelectAllBT

        Case ResetBT

    End Select
End Sub

Sub __UI_MouseUp (id As Long)
    Select Case id
        Case CheckboxTest

        Case LetuceCB

        Case TomatoCB

        Case MustardCB

        Case SandwitchContentsLB

        Case HamCB

        Case SelectAllBT

        Case ResetBT

    End Select
End Sub

Sub __UI_KeyPress (id As Long)
    'When this event is fired, __UI_KeyHit will contain the code of the key hit.
    'You can change it and even cancel it by making it = 0
    Select Case id
        Case LetuceCB

        Case TomatoCB

        Case MustardCB

        Case HamCB

        Case SelectAllBT

        Case ResetBT

    End Select
End Sub

Sub __UI_TextChanged (id As Long)
    Select Case id
    End Select
End Sub

Sub __UI_ValueChanged (id As Long)
    Select Case id
        Case LetuceCB

        Case TomatoCB

        Case MustardCB

        Case HamCB

    End Select
End Sub

Sub __UI_FormResized

End Sub

'$INCLUDE:'InForm/InForm.ui'


Form file CheckboxTest.frm


': This form was generated by
': InForm - GUI library for QB64 - v1.5
': Fellippe Heitor, 2016-2024 - fellippe@qb64.org - @fellippeheitor
': https://github.com/FellippeHeitor/InForm
'-----------------------------------------------------------
SUB __UI_LoadForm

    DIM __UI_NewID AS LONG, __UI_RegisterResult AS LONG

    __UI_NewID = __UI_NewControl(__UI_Type_Form, "CheckboxTest", 300, 300, 0, 0, 0)
    __UI_RegisterResult = 0
    SetCaption __UI_NewID, "Checkbox Test"
    Control(__UI_NewID).Font = SetFont("segoeui.ttf", 12)
    Control(__UI_NewID).HasBorder = False

    __UI_NewID = __UI_NewControl(__UI_Type_CheckBox, "LetuceCB", 150, 23, 16, 51, 0)
    __UI_RegisterResult = 0
    SetCaption __UI_NewID, "Lettuce"
    Control(__UI_NewID).HasBorder = False
    Control(__UI_NewID).Value = -1
    Control(__UI_NewID).CanHaveFocus = True

    __UI_NewID = __UI_NewControl(__UI_Type_CheckBox, "TomatoCB", 150, 23, 16, 79, 0)
    __UI_RegisterResult = 0
    SetCaption __UI_NewID, "Tomato"
    Control(__UI_NewID).HasBorder = False
    Control(__UI_NewID).CanHaveFocus = True

    __UI_NewID = __UI_NewControl(__UI_Type_CheckBox, "MustardCB", 150, 23, 16, 107, 0)
    __UI_RegisterResult = 0
    SetCaption __UI_NewID, "Mustard"
    Control(__UI_NewID).HasBorder = False
    Control(__UI_NewID).CanHaveFocus = True

    __UI_NewID = __UI_NewControl(__UI_Type_Label, "SandwitchContentsLB", 179, 29, 16, 17, 0)
    __UI_RegisterResult = 0
    SetCaption __UI_NewID, "Sandwitch contents"
    Control(__UI_NewID).Font = SetFont("segoeui.ttf", 18)
    Control(__UI_NewID).HasBorder = False
    Control(__UI_NewID).VAlign = __UI_Middle

    __UI_NewID = __UI_NewControl(__UI_Type_CheckBox, "HamCB", 150, 23, 16, 135, 0)
    __UI_RegisterResult = 0
    SetCaption __UI_NewID, "Ham"
    Control(__UI_NewID).HasBorder = False
    Control(__UI_NewID).CanHaveFocus = True

    __UI_NewID = __UI_NewControl(__UI_Type_Button, "SelectAllBT", 80, 23, 16, 193, 0)
    __UI_RegisterResult = 0
    SetCaption __UI_NewID, "Select ALL"
    Control(__UI_NewID).HasBorder = False
    Control(__UI_NewID).CanHaveFocus = True

    __UI_NewID = __UI_NewControl(__UI_Type_Button, "ResetBT", 80, 23, 127, 193, 0)
    __UI_RegisterResult = 0
    SetCaption __UI_NewID, "Reset"
    Control(__UI_NewID).HasBorder = False
    Control(__UI_NewID).CanHaveFocus = True

END SUB

SUB __UI_AssignIDs
    CheckboxTest = __UI_GetID("CheckboxTest")
    LetuceCB = __UI_GetID("LetuceCB")
    TomatoCB = __UI_GetID("TomatoCB")
    MustardCB = __UI_GetID("MustardCB")
    SandwitchContentsLB = __UI_GetID("SandwitchContentsLB")
    HamCB = __UI_GetID("HamCB")
    SelectAllBT = __UI_GetID("SelectAllBT")
    ResetBT = __UI_GetID("ResetBT")
END SUB


Events

Methods

Properties editable at runtime

See also: