logo

Toolbox Textbox

TextBox controls in an InForm application are used to receive text input from the user.

Textbox control

Create a new Textbox control by clicking the Textbox icon ToolBox text box 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 TextBox properties as necessary.

3) Textbox Properties:

ToolBox

Textbox examples: Preview window.

ToolBox example

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

Textbox examples refer to the above image.

E-mail:
To read back what was typed, you can use the Text array:

Var$ = Text(emailTB)

The SetCaption property and Caption array can be used to display a caption inside the textbox. The caption is hidden as soon as the user starts typing.

Caption(emailTB) = "Enter E-Mail"

Note: Before using the SetCaption property and Caption array to display a caption inside the textbox, you may need to first empty the text buffer if it contains user-entered text. For example:

Text(emailTB) = "" 

Password textbox:
With the PasswordField property, you can hide the text typed by a user using the Unicode character ● (UTF-8 e2978f).
You can set it at design time using the editor by checking the password mask option, or at runtime as follows:

Control(passwordTB).PasswordField = True

Note: A common practice is to associate a password textbox with a checkbox that allows the user to Hide/Show their input for quick spell checking.

Phone textbox:
The phone textbox example demonstrates the use of a masked input field. For details, refer to the Mask.

Specification: Let the textbox have the following design specification:

  1. Add the three textboxes as shown above.
  2. Include a button that, when clicked, displays the content entered into these text boxes.

Implimenation: The following provide solutions for the above:

Basic file Textbox_example.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 emailLB As Long
Dim Shared passwordLB As Long
Dim Shared PhoneLB As Long
Dim Shared emailTB As Long
Dim Shared phoneTB As Long
Dim Shared Button1 As Long
Dim Shared passwordTB As Long
Dim Shared TextboxExample As Long

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

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

End Sub

Sub __UI_OnLoad
    Caption(Button1) = "Read" '<---
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)
    Dim mailStr As String '       <---
    Dim passwordStr As String '   <---
    Dim phoneStr As String '      <---
    Dim phone2Str As String '     <---
    Dim stringTotal As String '    <---

    Select Case id
        Case emailLB

        Case passwordLB

        Case PhoneLB

        Case emailTB

        Case phoneTB

        Case Button1
            mailStr = Text(emailTB) '          <---
            passwordStr = Text(passwordTB) '   <---
            phoneStr = Text(phoneTB) '         <---
            phone2Str = RawText(phoneTB) '     <---

            stringTotal = "Mail     = " + mailStr + Chr$(10) '                   <---
            stringTotal = stringTotal + "Password = " + passwordStr + Chr$(10) ' <---
            stringTotal = stringTotal + "Phone    = " + phoneStr + Chr$(10) '    <---
            stringTotal = stringTotal + "Phone    = " + phone2Str '              <---

            _MessageBox "Read operation", stringTotal '                          <---
        Case passwordTB

        Case TextboxExample

    End Select
End Sub

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

        Case passwordLB

        Case PhoneLB

        Case emailTB

        Case phoneTB

        Case Button1

        Case passwordTB

        Case TextboxExample

    End Select
End Sub

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

        Case passwordLB

        Case PhoneLB

        Case emailTB

        Case phoneTB

        Case Button1

        Case passwordTB

        Case TextboxExample

    End Select
End Sub

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

        Case phoneTB

        Case Button1

        Case passwordTB

    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 emailTB

        Case phoneTB

        Case Button1

        Case passwordTB

    End Select
End Sub

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

        Case passwordLB

        Case PhoneLB

        Case emailTB

        Case phoneTB

        Case Button1

        Case passwordTB

        Case TextboxExample

    End Select
End Sub

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

        Case passwordLB

        Case PhoneLB

        Case emailTB

        Case phoneTB

        Case Button1

        Case passwordTB

        Case TextboxExample

    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 emailTB

        Case phoneTB

        Case Button1

        Case passwordTB

    End Select
End Sub

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

        Case phoneTB

        Case passwordTB

    End Select
End Sub

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

Sub __UI_FormResized

End Sub

'$INCLUDE:'InForm/InForm.ui'


Form fileTextbox_example.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, "TextboxExample", 300, 300, 0, 0, 0)
    __UI_RegisterResult = 0
    SetCaption __UI_NewID, "Textbox example"
    Control(__UI_NewID).Font = SetFont("segoeui.ttf", 12)
    Control(__UI_NewID).HasBorder = False

    __UI_NewID = __UI_NewControl(__UI_Type_TextBox, "passwordTB", 120, 23, 103, 84, 0)
    __UI_RegisterResult = 0
    SetCaption __UI_NewID, "password"
    Control(__UI_NewID).HasBorder = True
    Control(__UI_NewID).PasswordField = True
    Control(__UI_NewID).CanHaveFocus = True
    Control(__UI_NewID).BorderSize = 1

    __UI_NewID = __UI_NewControl(__UI_Type_Label, "emailLB", 62, 23, 36, 56, 0)
    __UI_RegisterResult = 0
    SetCaption __UI_NewID, "E-mail"
    Control(__UI_NewID).HasBorder = False
    Control(__UI_NewID).VAlign = __UI_Middle

    __UI_NewID = __UI_NewControl(__UI_Type_Label, "passwordLB", 62, 23, 36, 84, 0)
    __UI_RegisterResult = 0
    SetCaption __UI_NewID, "Password"
    Control(__UI_NewID).HasBorder = False
    Control(__UI_NewID).VAlign = __UI_Middle

    __UI_NewID = __UI_NewControl(__UI_Type_Label, "PhoneLB", 62, 23, 36, 112, 0)
    __UI_RegisterResult = 0
    SetCaption __UI_NewID, "Phone"
    Control(__UI_NewID).HasBorder = False
    Control(__UI_NewID).VAlign = __UI_Middle

    __UI_NewID = __UI_NewControl(__UI_Type_TextBox, "emailTB", 120, 23, 103, 56, 0)
    __UI_RegisterResult = 0
    Control(__UI_NewID).HasBorder = True
    Control(__UI_NewID).CanHaveFocus = True
    Control(__UI_NewID).BorderSize = 1

    __UI_NewID = __UI_NewControl(__UI_Type_TextBox, "phoneTB", 120, 23, 103, 112, 0)
    __UI_RegisterResult = 0
    Text(__UI_NewID) = "(___) _____-____"
    Mask(__UI_NewID) = "(000) 00000-0000"
    Control(__UI_NewID).HasBorder = True
    Control(__UI_NewID).CanHaveFocus = True
    Control(__UI_NewID).BorderSize = 1

    __UI_NewID = __UI_NewControl(__UI_Type_Button, "Button1", 80, 23, 78, 176, 0)
    __UI_RegisterResult = 0
    SetCaption __UI_NewID, "Button1"
    Control(__UI_NewID).HasBorder = False
    Control(__UI_NewID).CanHaveFocus = True

END SUB

SUB __UI_AssignIDs
    TextboxExample = __UI_GetID("TextboxExample")
    passwordTB = __UI_GetID("passwordTB")
    emailLB = __UI_GetID("emailLB")
    passwordLB = __UI_GetID("passwordLB")
    PhoneLB = __UI_GetID("PhoneLB")
    emailTB = __UI_GetID("emailTB")
    phoneTB = __UI_GetID("phoneTB")
    Button1 = __UI_GetID("Button1")
END SUB


Mask

The Mask array defines an input mask for Textbox controls. "0" serves as a placeholder for a digit, while any other characters are interpreted as literals.

Mask(phoneTB) = "(000) 00000-0000"

The Textbox control won't accept more characters than the total number of placeholders. The Text array holds the formatted output. Use the RawText$ method to read only the user input values.

a$ = Text(phoneTB) 'an example output using the mask above would be "(345) 555-7038"
b$ = RawText$(phoneTB) 'the sample output above would be returned as "3455557038"

 

Events

Methods

Properties editable at runtime

See also: