Reveal optional detail on demand
React to expanded and collapsed states.
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
{
"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 property | Value |
|---|---|
Caption | "Expander — McBasic" |
Width | 760 |
Height | 480 |
MinWidth | 600 |
MinHeight | 360 |
| Type | Name | Parent |
|---|---|---|
| Expander | expDetails | Form |
| Panel | pnlDetails | expDetails |
| Label | lblBody | pnlDetails |
| StatusBar | staStatus | Form |
| CommandButton | cmdClose | Form |
expDetails · exact Inspector values
| Property | Value |
|---|---|
Left | 32 |
Top | 28 |
Width | 640 |
Height | 286 |
Header | "Details" |
IsExpanded | True |
ExpandDirection | "Down" |
TabIndex | 0 |
| Anchor edges | Left, Right, Top |
pnlDetails · exact Inspector values
| Property | Value |
|---|---|
Left | 16 |
Top | 18 |
Width | 600 |
Height | 210 |
TabIndex | 0 |
| Anchor edges | Left, Right, Top |
lblBody · exact Inspector values
| Property | Value |
|---|---|
Left | 24 |
Top | 24 |
Width | 520 |
Height | 36 |
Caption | "This content lives inside the Expander." |
TabIndex | 0 |
| Anchor edges | Left, Top |
staStatus · exact Inspector values
| Property | Value |
|---|---|
Left | 32 |
Top | 360 |
Width | 470 |
Height | 28 |
Text | "Ready" |
TabIndex | 1 |
| Anchor edges | Left, Bottom |
cmdClose · exact Inspector values
| Property | Value |
|---|---|
Left | 560 |
Top | 354 |
Width | 112 |
Height | 36 |
Caption | "Close" |
TabIndex | 2 |
| Anchor edges | Right, Bottom |
Step 3Connect the events explicitly#
frmMain
| Object | Event | Procedure | Parameters |
|---|---|---|---|
expDetails | Expanded | expDetails_Expanded | Expanded() |
expDetails | Collapsed | expDetails_Collapsed | Collapsed() |
cmdClose | Click | cmdClose_Click | Click() |
| Form | Load | Form_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.
Option ExplicitPrivate Sub Form_Load()
Initialize state before enabling dependent actions. Keep the shared declarations and startup dependencies with this procedure.
Private Sub Form_Load()
expDetails.Header = "Details"
expDetails.IsExpanded = True
expDetails.ExpandDirection = "Down"
staStatus.Text = "Expander ready"
End SubPrivate Sub expDetails_Expanded()
Enter this helper in the named source file, outside every other procedure. Its callers are included in the same project.
Private Sub expDetails_Expanded()
staStatus.Text = "Expanded"
End SubPrivate Sub expDetails_Collapsed()
Enter this helper in the named source file, outside every other procedure. Its callers are included in the same project.
Private Sub expDetails_Collapsed()
staStatus.Text = "Collapsed"
End SubPrivate Sub cmdClose_Click()
Enter the complete action, including its input checks and calls to helper procedures.
Private Sub cmdClose_Click()
Unload Me
End SubCopy the complete Forms/frmMain.bas file
Replace the file once; do not append duplicate procedures.
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 SubStep 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:
mcbasic check Expander.mcbproj
mcbasic run Expander.mcbprojAcceptance 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.
20f4bfed6b · Build manifest