McBasic™Get McBasic™ ↗
Build 881
Hands-on tutorial · Layout & Forms

Reveal optional detail on demand

React to expanded and collapsed states.

1 Form / control designs1 complete BASIC filesGuided sample project

An Expander is useful for secondary content that should not dominate the first view. Expanded and Collapsed are state transitions; update the surrounding status accordingly. The contents must remain usable when opened and must not leave a misleading status when closed.

Step 1Prepare a safe practice project#

Extract the archive into a new writable folder, separate from your own application. Open Expander.mcbproj in McBasic™. Keep every declared source, layout, resource and migration file together.

To reconstruct it yourself, create a DesktopApp project and add the files declared below. In the complete project, follow these steps as a guided rebuild: replace each named source file once and Check after all its procedures are present.

Exact project configuration
project.mcproj
{
  "schemaVersion": 1,
  "projectId": "8f4a4dfd-3bb2-4e0e-a0a2-7cfe9ad42386",
  "name": "ExpanderSample",
  "kind": "DesktopApp",
  "ai": {
    "storeChatsInProject": false
  },
  "language": {
    "dialect": "McBasic1",
    "requireExplicit": true,
    "compare": "Binary",
    "defaultArrayBase": 0
  },
  "application": {
    "bundleIdentifier": "com.mcbasic.samples.expander",
    "version": "0.1.0",
    "buildNumber": "1",
    "startupFormId": "form-main",
    "shutdownMode": "OnStartupFormClosed"
  },
  "forms": [
    {
      "id": "form-main",
      "typeName": "frmMain",
      "layout": "Forms/frmMain.form.json",
      "code": "Forms/frmMain.bas"
    }
  ],
  "modules": [],
  "classes": [],
  "tests": [],
  "references": [],
  "resources": [],
  "targets": [
    "osx-arm64"
  ],
  "capabilities": []
}

Step 2Build the Form and set its properties#

frmMain

Select the Form first and set its properties. Add containers before their children. These are initial Designer values, not statements to paste into a procedure.

Form propertyValue
Caption"Expander — McBasic"
Width760
Height480
MinWidth600
MinHeight360
TypeNameParent
ExpanderexpDetailsForm
PanelpnlDetailsexpDetails
LabellblBodypnlDetails
StatusBarstaStatusForm
CommandButtoncmdCloseForm
expDetails · exact Inspector values
PropertyValue
Left32
Top28
Width640
Height286
Header"Details"
IsExpandedTrue
ExpandDirection"Down"
TabIndex0
Anchor edgesLeft, Right, Top
pnlDetails · exact Inspector values
PropertyValue
Left16
Top18
Width600
Height210
TabIndex0
Anchor edgesLeft, Right, Top
lblBody · exact Inspector values
PropertyValue
Left24
Top24
Width520
Height36
Caption"This content lives inside the Expander."
TabIndex0
Anchor edgesLeft, Top
staStatus · exact Inspector values
PropertyValue
Left32
Top360
Width470
Height28
Text"Ready"
TabIndex1
Anchor edgesLeft, Bottom
cmdClose · exact Inspector values
PropertyValue
Left560
Top354
Width112
Height36
Caption"Close"
TabIndex2
Anchor edgesRight, Bottom

Step 3Connect the events explicitly#

frmMain

ObjectEventProcedureParameters
expDetailsExpandedexpDetails_ExpandedExpanded()
expDetailsCollapsedexpDetails_CollapsedCollapsed()
cmdCloseClickcmdClose_ClickClick()
FormLoadForm_Load()

Step 4Enter the complete behavior#

Open the named source file. Enter declarations first, then every procedure. Expand a procedure for its full body, or copy the complete file. Helpers are required: do not stop after entering the first Click handler.

Forms/frmMain.bas

Enter these declarations at file scope, before the procedures.

Forms/frmMain.bas · declarations
Option Explicit
Private Sub Form_Load()

Initialize state before enabling dependent actions. Keep the shared declarations and startup dependencies with this procedure.

Forms/frmMain.bas · Form_Load
Private Sub Form_Load()
    expDetails.Header = "Details"
    expDetails.IsExpanded = True
    expDetails.ExpandDirection = "Down"
    staStatus.Text = "Expander ready"
End Sub
Private Sub expDetails_Expanded()

Enter this helper in the named source file, outside every other procedure. Its callers are included in the same project.

Forms/frmMain.bas · expDetails_Expanded
Private Sub expDetails_Expanded()
    staStatus.Text = "Expanded"
End Sub
Private Sub expDetails_Collapsed()

Enter this helper in the named source file, outside every other procedure. Its callers are included in the same project.

Forms/frmMain.bas · expDetails_Collapsed
Private Sub expDetails_Collapsed()
    staStatus.Text = "Collapsed"
End Sub
Private Sub cmdClose_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdClose_Click
Private Sub cmdClose_Click()
    Unload Me
End Sub
Copy the complete Forms/frmMain.bas file

Replace the file once; do not append duplicate procedures.

Forms/frmMain.bas
Option Explicit

Private Sub Form_Load()
    expDetails.Header = "Details"
    expDetails.IsExpanded = True
    expDetails.ExpandDirection = "Down"
    staStatus.Text = "Expander ready"
End Sub

Private Sub expDetails_Expanded()
    staStatus.Text = "Expanded"
End Sub

Private Sub expDetails_Collapsed()
    staStatus.Text = "Collapsed"
End Sub

Private Sub cmdClose_Click()
    Unload Me
End Sub

Step 5Keep resources and storage reproducible#

No external resource or migration files are declared. Any inline migration, seed data or local JSON is present in the code above. Runtime application data and private preferences are not included in the archive.

Step 6Check, run and test the result#

Save all files and run Check. Resolve diagnostics before Run. Developer CLI users can work from the extracted folder:

Developer CLI
mcbasic check Expander.mcbproj
mcbasic run Expander.mcbproj

Acceptance checklist

  • Expand the details and inspect the status.
  • Collapse them and inspect the second status.
  • Repeat using keyboard focus.

Step 7Make one change and repeat the tests#

Place an optional settings field inside the details area and verify its value survives collapse.

Save a working Git checkpoint first. Change one behavior, Check again and repeat the acceptance checklist. Compare with the downloaded solution if a regression appears.

Source baseline 20f4bfed6b · Build manifest