Skip to content

Panel

The Panel widget is a collapsible frame that can expand and collapse to show or hide its contents.

Panel extends Frame and adds collapsible functionality. When collapsed, only the header is visible. When expanded, the full panel with all children is shown.

Whether the panel is currently collapsed.

panel.Collapsed = true; // Collapse the panel

The panel header text. The header displays a collapse/expand indicator (▼/▶).

panel.Header = "Advanced Settings";

Toggles the collapsed state.

panel.Toggle();

Expands the panel.

panel.Expand();

Collapses the panel.

panel.Collapse();
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 toggle
  • Space or Enter: Toggle collapsed state
  • Mouse Click on header: Toggle collapsed state
  • 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