Table of Contents

Class SliderControl

Namespace
SharpConsoleUI.Controls
Assembly
SharpConsoleUI.dll

A slider control that allows users to select a value from a range by dragging a thumb along a track. Supports both horizontal and vertical orientations, keyboard and mouse interaction, and optional value and min/max labels.

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

Constructors

SliderControl()

Initializes a new instance of the SliderControl class.

public SliderControl()

Properties

BackgroundColor

Gets or sets the background color.

public Color? BackgroundColor { get; set; }

Property Value

Color?

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

Container

Gets or sets the parent container that hosts this control.

public override IContainer? Container { get; set; }

Property Value

IContainer

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?

FilledTrackColor

Gets or sets the color of the filled track portion.

public Color? FilledTrackColor { get; set; }

Property Value

Color?

FocusedThumbColor

Gets or sets the color of the thumb indicator when focused.

public Color? FocusedThumbColor { get; set; }

Property Value

Color?

HasFocus

public bool HasFocus { get; }

Property Value

bool

IsDragging

Gets whether the slider is currently being dragged.

public bool IsDragging { get; }

Property Value

bool

IsEnabled

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

public bool IsEnabled { get; set; }

Property Value

bool

LargeStep

Gets or sets the large step increment used for Page Up/Down and Shift+Arrow.

public double LargeStep { get; set; }

Property Value

double

MaxValue

Gets or sets the maximum value of the slider range.

public double MaxValue { get; set; }

Property Value

double

MinValue

Gets or sets the minimum value of the slider range.

public double MinValue { get; set; }

Property Value

double

Orientation

Gets or sets the slider orientation.

public SliderOrientation Orientation { get; set; }

Property Value

SliderOrientation

ShowMinMaxLabels

Gets or sets whether to show the min and max value labels at the track ends.

public bool ShowMinMaxLabels { get; set; }

Property Value

bool

ShowValueLabel

Gets or sets whether to show the current value label next to the slider.

public bool ShowValueLabel { get; set; }

Property Value

bool

Step

Gets or sets the step increment. Must be at least SliderMinStep.

public double Step { get; set; }

Property Value

double

ThumbColor

Gets or sets the color of the thumb indicator.

public Color? ThumbColor { get; set; }

Property Value

Color?

TrackColor

Gets or sets the color of the unfilled track portion.

public Color? TrackColor { get; set; }

Property Value

Color?

Value

Gets or sets the current slider value. Clamped to [MinValue, MaxValue] and snapped to Step.

public double Value { get; set; }

Property Value

double

ValueLabelFormat

Gets or sets the format string for the value label (default: "F0").

public string ValueLabelFormat { get; set; }

Property Value

string

WantsMouseEvents

Whether this control wants to receive mouse events

public bool WantsMouseEvents { get; }

Property Value

bool

Methods

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. Override to perform control-specific cleanup (null events, close portals, clear data, etc.).

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

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

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>

ValueChanged

Occurs when the slider value changes.

public event EventHandler<double>? ValueChanged

Event Type

EventHandler<double>