Table of Contents

Class PanelControl

Namespace
SharpConsoleUI.Controls
Assembly
SharpConsoleUI.dll

A control that renders a bordered panel with content. Renders directly to CharacterBuffer using BoxChars and MarkupParser.

public class PanelControl : BaseControl, IDOMPaintable, INotifyPropertyChanged, IMouseAwareControl, IWindowControl, IDisposable
Inheritance
PanelControl
Implements
Inherited Members
Extension Methods

Constructors

PanelControl()

Initializes a new instance of the PanelControl class.

public PanelControl()

PanelControl(string)

Initializes a new instance of the PanelControl class with text content.

public PanelControl(string text)

Parameters

text string

The text to display inside the panel (supports markup).

Properties

BackgroundColor

Gets or sets the background color. When null, inherits from the container.

public Color? BackgroundColor { get; set; }

Property Value

Color?

BorderColor

Gets or sets the border color. When null, uses the resolved foreground color.

public Color? BorderColor { get; set; }

Property Value

Color?

BorderStyle

Gets or sets the border style for the panel.

public BorderStyle BorderStyle { get; set; }

Property Value

BorderStyle

CanFocusWithMouse

Whether this control can receive focus via mouse clicks

public bool CanFocusWithMouse { get; set; }

Property Value

bool

Content

Gets or sets the content to display inside the panel (supports markup).

public string? Content { get; set; }

Property Value

string

ContentWidth

Gets the minimum width needed to display the control's content, including margins. Returns null if width cannot be determined. This is calculated based on content (text length, child controls, etc.) and represents the natural/intrinsic size.

public override int? ContentWidth { get; }

Property Value

int?

ForegroundColor

Gets or sets the foreground color. When null, inherits from the container.

public Color? ForegroundColor { get; set; }

Property Value

Color?

Header

Gets or sets the header text displayed at the top of the panel border.

public string? Header { get; set; }

Property Value

string

HeaderAlignment

Gets or sets the horizontal alignment of the header text.

public TextJustification HeaderAlignment { get; set; }

Property Value

TextJustification

Height

Gets or sets the explicit height of the panel. When set, the panel border will render at this height. When null and VerticalAlignment is Fill, the panel stretches to fill available height.

public override int? Height { get; set; }

Property Value

int?

Padding

Gets or sets the padding inside the panel border.

public Padding Padding { get; set; }

Property Value

Padding

UseSafeBorder

Gets or sets whether to use safe border characters for better terminal compatibility.

public bool UseSafeBorder { get; set; }

Property Value

bool

WantsMouseEvents

Whether this control wants to receive mouse events

public bool WantsMouseEvents { get; set; }

Property Value

bool

WordWrap

Gets or sets whether content lines that exceed the panel width are word-wrapped. When true (default), long lines are broken at word boundaries. When false, long lines are clipped at the panel boundary — use this for pre-formatted content such as graphs and progress bars.

public bool WordWrap { get; set; }

Property Value

bool

Methods

Create()

Creates a new builder for configuring a PanelControl

public static PanelBuilder Create()

Returns

PanelBuilder

A new builder instance

GetLogicalContentSize()

Gets the logical size of the control's content without rendering.

public override Size GetLogicalContentSize()

Returns

Size

The size representing the content's natural dimensions.

MeasureDOM(LayoutConstraints)

Measures the control's desired size given the available constraints.

public override LayoutSize MeasureDOM(LayoutConstraints constraints)

Parameters

constraints LayoutConstraints

The layout constraints (min/max width/height).

Returns

LayoutSize

The desired size of the control.

OnDisposing()

Called during Dispose before Container is set to null. Clears mouse event handlers to prevent memory leaks.

protected override void OnDisposing()

PaintDOM(CharacterBuffer, LayoutRect, LayoutRect, Color, Color)

Paints the control's content directly to a CharacterBuffer.

public override void PaintDOM(CharacterBuffer buffer, LayoutRect bounds, LayoutRect clipRect, Color defaultFg, Color defaultBg)

Parameters

buffer CharacterBuffer

The buffer to paint to.

bounds LayoutRect

The absolute bounds where the control should paint.

clipRect LayoutRect

The clipping rectangle (visible area).

defaultFg Color
defaultBg Color

ProcessMouseEvent(MouseEventArgs)

Processes a mouse event for this control

public bool ProcessMouseEvent(MouseEventArgs args)

Parameters

args MouseEventArgs

Mouse event arguments with control-relative coordinates

Returns

bool

True if the event was handled and should not propagate further

SetContent(string)

Sets the content to display inside the panel using text (supports markup).

public void SetContent(string text)

Parameters

text string

The text to display.

Events

MouseClick

Event fired when the control is clicked

public event EventHandler<MouseEventArgs>? MouseClick

Event Type

EventHandler<MouseEventArgs>

MouseDoubleClick

Event fired when the control is double-clicked

public event EventHandler<MouseEventArgs>? MouseDoubleClick

Event Type

EventHandler<MouseEventArgs>

MouseEnter

Event fired when the mouse enters the control area

public event EventHandler<MouseEventArgs>? MouseEnter

Event Type

EventHandler<MouseEventArgs>

MouseLeave

Event fired when the mouse leaves the control area

public event EventHandler<MouseEventArgs>? MouseLeave

Event Type

EventHandler<MouseEventArgs>

MouseMove

Event fired when the mouse moves over the control

public event EventHandler<MouseEventArgs>? MouseMove

Event Type

EventHandler<MouseEventArgs>

MouseRightClick

Event fired when the control is right-clicked (Button3)

public event EventHandler<MouseEventArgs>? MouseRightClick

Event Type

EventHandler<MouseEventArgs>