Table of Contents

Class CheckboxControl

Namespace
SharpConsoleUI.Controls
Assembly
SharpConsoleUI.dll

A toggleable checkbox control that displays a label and checked/unchecked state. Supports keyboard interaction with Space or Enter keys to toggle state.

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

Constructors

CheckboxControl(string, bool)

Initializes a new instance of the CheckboxControl class.

public CheckboxControl(string label = "Checkbox", bool isChecked = false)

Parameters

label string

The text label displayed next to the checkbox.

isChecked bool

The initial checked state of the checkbox.

Properties

BackgroundColor

Gets or sets the background color of the checkbox in its normal state.

public Color? BackgroundColor { get; set; }

Property Value

Color?

CanFocusWithMouse

Gets whether the checkbox can receive focus via mouse click. Only can focus when enabled.

public bool CanFocusWithMouse { get; }

Property Value

bool

CanReceiveFocus

Whether this control can receive focus

public bool CanReceiveFocus { get; }

Property Value

bool

Checked

Gets or sets the checked state of the checkbox.

public bool Checked { get; set; }

Property Value

bool

CheckmarkColor

Gets or sets the color of the checkmark character when checked.

public Color CheckmarkColor { get; set; }

Property Value

Color

ContentWidth

Gets the actual rendered width of the control based on content.

public override int? ContentWidth { get; }

Property Value

int?

DisabledBackgroundColor

Gets or sets the background color when the control is disabled.

public Color? DisabledBackgroundColor { get; set; }

Property Value

Color?

DisabledForegroundColor

Gets or sets the foreground color when the control is disabled.

public Color DisabledForegroundColor { get; set; }

Property Value

Color

FocusedBackgroundColor

Gets or sets the background color when the control has focus.

public Color? FocusedBackgroundColor { get; set; }

Property Value

Color?

FocusedForegroundColor

Gets or sets the foreground color when the control has focus.

public Color FocusedForegroundColor { get; set; }

Property Value

Color

ForegroundColor

Gets or sets the foreground color of the checkbox in its normal state.

public Color ForegroundColor { get; set; }

Property Value

Color

HasFocus

public bool HasFocus { get; }

Property Value

bool

IsEnabled

Gets or sets whether the checkbox is enabled and can be interacted with.

public bool IsEnabled { get; set; }

Property Value

bool

Label

Gets or sets the label text displayed next to the checkbox.

public string Label { get; set; }

Property Value

string

WantsMouseEvents

Gets whether the checkbox wants to receive mouse events. Only receives events when enabled.

public bool WantsMouseEvents { get; }

Property Value

bool

Methods

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.

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

ProcessKey(ConsoleKeyInfo)

Processes a keyboard input event.

public bool ProcessKey(ConsoleKeyInfo key)

Parameters

key ConsoleKeyInfo

The key information for the pressed key.

Returns

bool

True if the key was handled by this control; otherwise, false.

ProcessMouseEvent(MouseEventArgs)

Processes mouse events for the checkbox. Handles clicks to toggle the checked state and capture focus.

public bool ProcessMouseEvent(MouseEventArgs args)

Parameters

args MouseEventArgs

Returns

bool

Toggle()

Toggles the checked state of the checkbox.

public void Toggle()

Events

CheckedChanged

Occurs when the checked state of the checkbox changes.

public event EventHandler<bool>? CheckedChanged

Event Type

EventHandler<bool>

MouseClick

Occurs when the checkbox is clicked with the mouse.

public event EventHandler<MouseEventArgs>? MouseClick

Event Type

EventHandler<MouseEventArgs>

MouseDoubleClick

Occurs when the checkbox is double-clicked with the mouse.

public event EventHandler<MouseEventArgs>? MouseDoubleClick

Event Type

EventHandler<MouseEventArgs>

MouseEnter

Occurs when the mouse enters the checkbox area.

public event EventHandler<MouseEventArgs>? MouseEnter

Event Type

EventHandler<MouseEventArgs>

MouseLeave

Occurs when the mouse leaves the checkbox area.

public event EventHandler<MouseEventArgs>? MouseLeave

Event Type

EventHandler<MouseEventArgs>

MouseMove

Occurs when the mouse moves over the checkbox.

public event EventHandler<MouseEventArgs>? MouseMove

Event Type

EventHandler<MouseEventArgs>

MouseRightClick

Occurs when the checkbox is right-clicked with the mouse.

public event EventHandler<MouseEventArgs>? MouseRightClick

Event Type

EventHandler<MouseEventArgs>