Organize controls with panels
Understand parenting, nested layout and inherited interaction state.
A child’s coordinates are relative to its parent. Moving a panel should move its visual group together. Enabled and Visible affect a group differently: test child interaction as well as appearance. Do not simulate a container by merely placing a rectangle behind unrelated controls.
Step 1Prepare a safe practice project#
Extract the archive into a new writable folder, separate from your own application. Open PanelGallery.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": "d4a0f4af-8887-49e2-9b9f-5c171b2ff032",
"name": "PanelGallery",
"kind": "DesktopApp",
"ai": {
"storeChatsInProject": false
},
"language": {
"dialect": "McBasic1",
"requireExplicit": true,
"compare": "Binary",
"defaultArrayBase": 0
},
"application": {
"bundleIdentifier": "com.mcbasic.panelgallery",
"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 | "PanelGallery — BASIC containers" |
Width | 560 |
Height | 420 |
| Type | Name | Parent |
|---|---|---|
| Panel | pnlOuter | Form |
| Panel | pnlInner | pnlOuter |
| Label | lblTitle | pnlOuter |
| Label | lblClipped | pnlInner |
| CommandButton | cmdNested | pnlInner |
| Label | lblState | Form |
| CommandButton | cmdEnabled | Form |
| CommandButton | cmdVisible | Form |
pnlOuter · exact Inspector values
| Property | Value |
|---|---|
Left | 24 |
Top | 40 |
Width | 480 |
Height | 220 |
Padding | "12,16,12,16" |
| Anchor edges | Left, Top |
pnlInner · exact Inspector values
| Property | Value |
|---|---|
Left | 30 |
Top | 48 |
Width | 310 |
Height | 140 |
Padding | "8" |
| Anchor edges | Left, Top |
lblTitle · exact Inspector values
| Property | Value |
|---|---|
Left | 12 |
Top | 12 |
Width | 430 |
Height | 28 |
Caption | "Outer panel — coordinates relative to its origin" |
| Anchor edges | Left, Top |
lblClipped · exact Inspector values
| Property | Value |
|---|---|
Left | 240 |
Top | 12 |
Width | 190 |
Height | 28 |
Caption | "Clipped at panel boundary" |
| Anchor edges | Left, Top |
cmdNested · exact Inspector values
| Property | Value |
|---|---|
Left | 18 |
Top | 70 |
Width | 210 |
Height | 34 |
Caption | "Nested BASIC action" |
ZIndex | 3 |
| Anchor edges | Left, Top |
lblState · exact Inspector values
| Property | Value |
|---|---|
Left | 24 |
Top | 276 |
Width | 490 |
Height | 30 |
Caption | "Loading panels" |
| Anchor edges | Left, Top |
cmdEnabled · exact Inspector values
| Property | Value |
|---|---|
Left | 24 |
Top | 324 |
Width | 220 |
Height | 36 |
Caption | "Toggle panel enabled" |
| Anchor edges | Left, Top |
cmdVisible · exact Inspector values
| Property | Value |
|---|---|
Left | 268 |
Top | 324 |
Width | 240 |
Height | 36 |
Caption | "Toggle panel visible" |
| Anchor edges | Left, Top |
Step 3Connect the events explicitly#
frmMain
| Object | Event | Procedure | Parameters |
|---|---|---|---|
cmdNested | Click | cmdNested_Click | Click() |
cmdEnabled | Click | cmdEnabled_Click | Click() |
cmdVisible | Click | cmdVisible_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 Explicit
Private clicks As LongPrivate Sub Form_Load()
Initialize state before enabling dependent actions. Keep the shared declarations and startup dependencies with this procedure.
Private Sub Form_Load()
pnlOuter.Tag = 42
pnlInner.Tag = "nested-container"
pnlOuter.Padding = "12,16,12,16"
pnlInner.Padding = "8"
cmdNested.ZIndex = 3
lblState.Caption = "Panels ready — Tag " & TypeName(pnlOuter.Tag) & " " & CStr(pnlOuter.Tag)
End SubPrivate Sub cmdNested_Click()
Enter the complete action, including its input checks and calls to helper procedures.
Private Sub cmdNested_Click()
clicks = clicks + 1
lblState.Caption = "Nested BASIC clicks: " & CStr(clicks)
End SubPrivate Sub cmdEnabled_Click()
Enter the complete action, including its input checks and calls to helper procedures.
Private Sub cmdEnabled_Click()
pnlOuter.Enabled = Not pnlOuter.Enabled
lblState.Caption = "Panel enabled: " & CStr(pnlOuter.Enabled)
End SubPrivate Sub cmdVisible_Click()
Enter the complete action, including its input checks and calls to helper procedures.
Private Sub cmdVisible_Click()
pnlOuter.Visible = Not pnlOuter.Visible
lblState.Caption = "Panel visible: " & CStr(pnlOuter.Visible)
End SubCopy the complete Forms/frmMain.bas file
Replace the file once; do not append duplicate procedures.
Option Explicit
Private clicks As Long
Private Sub Form_Load()
pnlOuter.Tag = 42
pnlInner.Tag = "nested-container"
pnlOuter.Padding = "12,16,12,16"
pnlInner.Padding = "8"
cmdNested.ZIndex = 3
lblState.Caption = "Panels ready — Tag " & TypeName(pnlOuter.Tag) & " " & CStr(pnlOuter.Tag)
End Sub
Private Sub cmdNested_Click()
clicks = clicks + 1
lblState.Caption = "Nested BASIC clicks: " & CStr(clicks)
End Sub
Private Sub cmdEnabled_Click()
pnlOuter.Enabled = Not pnlOuter.Enabled
lblState.Caption = "Panel enabled: " & CStr(pnlOuter.Enabled)
End Sub
Private Sub cmdVisible_Click()
pnlOuter.Visible = Not pnlOuter.Visible
lblState.Caption = "Panel visible: " & CStr(pnlOuter.Visible)
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 PanelGallery.mcbproj
mcbasic run PanelGallery.mcbprojAcceptance checklist
- Use the nested panel action.
- Toggle Enabled and try a child command.
- Toggle Visible and restore the group.
- Resize the Form and inspect the nested geometry.
Step 7Make one change and repeat the tests#
Move a related set of controls into one panel while preserving their tab order.
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