Panel
The Panel widget is a collapsible frame that can expand and collapse to show or hide its contents.
Overview
Section titled “Overview”Panel extends Frame and adds collapsible functionality. When collapsed, only the header is visible. When expanded, the full panel with all children is shown.
Properties
Section titled “Properties”Collapsed (bool)
Section titled “Collapsed (bool)”Whether the panel is currently collapsed.
panel.Collapsed = true; // Collapse the panelHeader (string)
Section titled “Header (string)”The panel header text. The header displays a collapse/expand indicator (▼/▶).
panel.Header = "Advanced Settings";Methods
Section titled “Methods”Toggle()
Section titled “Toggle()”Toggles the collapsed state.
panel.Toggle();Expand()
Section titled “Expand()”Expands the panel.
panel.Expand();Collapse()
Section titled “Collapse()”Collapses the panel.
panel.Collapse();Usage Example
Section titled “Usage Example”var panel = new Panel("Advanced Options"){ X = 5, Y = 5, Width = 50, Height = 15, BorderStyle = BorderStyle.Single, ForegroundColor = Color.White};
var option1 = new Checkbox("Enable feature A");var option2 = new Checkbox("Enable feature B");
panel.Add(option1);panel.Add(option2);
// Panel starts expanded by default// User can press Space or Enter to toggleKeyboard Interaction
Section titled “Keyboard Interaction”- Space or Enter: Toggle collapsed state
- Mouse Click on header: Toggle collapsed state
Behavior
Section titled “Behavior”-
When collapsed:
- Height is set to 3 (minimum for header)
- All children are hidden (
Visible = false) - Header shows ▶ indicator
-
When expanded:
- Height is restored to previous value
- All children are shown (
Visible = true) - Header shows ▼ indicator