Table of Contents

Class ButtonControl

Namespace
SharpConsoleUI.Controls
Assembly
SharpConsoleUI.dll

A clickable button control that supports keyboard and mouse interaction.

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

Constructors

ButtonControl()

Initializes a new instance of the ButtonControl class with default settings.

public ButtonControl()

Properties

BackgroundColor

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

public Color? BackgroundColor { get; set; }

Property Value

Color?

BorderColor

public Color? BorderColor { get; set; }

Property Value

Color?

ButtonBorder

public ButtonBorderStyle ButtonBorder { get; set; }

Property Value

ButtonBorderStyle

CanFocusWithMouse

Whether this control can receive focus via mouse clicks

public bool CanFocusWithMouse { get; }

Property Value

bool

CanReceiveFocus

Whether this control can receive focus

public bool CanReceiveFocus { get; }

Property Value

bool

ContentWidth

Gets the actual rendered width of the button in characters.

public override int? ContentWidth { get; }

Property Value

int?

DisabledBackgroundColor

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

public Color? DisabledBackgroundColor { get; set; }

Property Value

Color?

DisabledForegroundColor

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

public Color DisabledForegroundColor { get; set; }

Property Value

Color

FocusedBackgroundColor

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

public Color? FocusedBackgroundColor { get; set; }

Property Value

Color?

FocusedForegroundColor

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

public Color FocusedForegroundColor { get; set; }

Property Value

Color

ForegroundColor

Gets or sets the foreground color of the button 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 button is enabled and can be interacted with.

public bool IsEnabled { get; set; }

Property Value

bool

Text

Gets or sets the text displayed on the button.

public string Text { get; set; }

Property Value

string

WantsMouseEvents

Whether this control wants to receive mouse events

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 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

Events

Click

Event fired when the button is clicked (convenience event that provides the button as parameter).

public event EventHandler<ButtonControl>? Click

Event Type

EventHandler<ButtonControl>

MouseClick

Event fired when the button is clicked (by mouse or keyboard).

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

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

public event EventHandler<MouseEventArgs>? MouseRightClick

Event Type

EventHandler<MouseEventArgs>