Table of Contents

Class TabControl

Namespace
SharpConsoleUI.Controls
Assembly
SharpConsoleUI.dll

A tab control that displays multiple pages of content, with tab headers for switching between them. Uses visibility toggling to show/hide tab content efficiently.

public class TabControl : BaseControl, IDOMPaintable, INotifyPropertyChanged, IContainer, IMouseAwareControl, IInteractiveControl, IContainerControl, IFocusableControl, IWindowControl, IDisposable, IFocusableContainerWithHeader
Inheritance
TabControl
Implements
Inherited Members
Extension Methods

Constructors

TabControl()

Initializes a new instance of the TabControl class.

public TabControl()

Properties

ActiveTab

Gets the currently active tab page, or null if no tabs exist.

public TabPage? ActiveTab { get; }

Property Value

TabPage

ActiveTabIndex

Gets or sets the index of the currently active tab.

public int ActiveTabIndex { get; set; }

Property Value

int

BackgroundColor

Gets or sets the background color for the container and its child controls.

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?

ForegroundColor

Gets or sets the foreground (text) color for the container and its child controls.

public Color ForegroundColor { get; set; }

Property Value

Color

GetConsoleWindowSystem

Gets the console window system instance, or null if not attached to a window system.

public ConsoleWindowSystem? GetConsoleWindowSystem { get; }

Property Value

ConsoleWindowSystem

HasFocus

public bool HasFocus { get; }

Property Value

bool

HasTabs

Gets whether the control has any tabs.

public bool HasTabs { get; }

Property Value

bool

HeaderStyle

Gets or sets the visual style used to render the tab header area.

public TabHeaderStyle HeaderStyle { get; set; }

Property Value

TabHeaderStyle

Height

Gets or sets the explicit height of the control. Minimum height is 2 (1 for header, 1 for content).

public override int? Height { get; set; }

Property Value

int?

IsDirty

Gets or sets whether this container needs to be redrawn.

public bool IsDirty { get; set; }

Property Value

bool

IsEnabled

Gets or sets whether this control is enabled and can receive input.

public bool IsEnabled { get; set; }

Property Value

bool

SelectOnRightClick

Gets or sets whether a right-click on a tab header selects that tab before firing the MouseRightClick event. Default: false (preserves backward compatibility).

public bool SelectOnRightClick { get; set; }

Property Value

bool

TabCount

Gets the number of tabs in the control.

public int TabCount { get; }

Property Value

int

TabHeaderHeight

Returns the number of rows consumed by the tab header (1 for Classic, 2 for Separator/AccentedSeparator).

public int TabHeaderHeight { get; }

Property Value

int

TabPages

Gets the read-only list of tab pages.

public IReadOnlyList<TabPage> TabPages { get; }

Property Value

IReadOnlyList<TabPage>

TabTitles

Gets the titles of all tabs.

public IEnumerable<string> TabTitles { get; }

Property Value

IEnumerable<string>

WantsMouseEvents

Whether this control wants to receive mouse events

public bool WantsMouseEvents { get; }

Property Value

bool

Methods

AddTab(string, IWindowControl, bool)

Adds a new tab to the control.

public void AddTab(string title, IWindowControl content, bool isClosable = false)

Parameters

title string

The title displayed in the tab header.

content IWindowControl

The control to display when this tab is active.

isClosable bool

When true, a × close button is shown in the tab header.

ClearTabs()

Removes all tabs from the control.

public void ClearTabs()

FindTab(string)

Finds a tab by title.

public TabPage? FindTab(string title)

Parameters

title string

The title to search for.

Returns

TabPage

The tab page, or null if not found.

GetChildren()

Gets the direct child controls of this container. Does not recursively include grandchildren - recursion happens in caller.

public IReadOnlyList<IWindowControl> GetChildren()

Returns

IReadOnlyList<IWindowControl>

Read-only list of direct child controls (may include other containers)

Remarks

IMPORTANT: For HorizontalGridControl, this should return columns AND splitters in order: [Column1, Splitter1, Column2, Splitter2, Column3]

Splitters are IInteractiveControl and should be included in Tab navigation.

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.

GetTab(int)

Gets a tab by index.

public TabPage? GetTab(int index)

Parameters

index int

The index of the tab.

Returns

TabPage

The tab page, or null if index is out of range.

GetVisibleHeightForControl(IWindowControl)

Gets the actual visible height for a control within the container viewport. Returns null if the control is not found or visibility cannot be determined.

public int? GetVisibleHeightForControl(IWindowControl control)

Parameters

control IWindowControl

The control to check

Returns

int?

The number of visible lines, or null if unknown

HasTab(string)

Checks if a tab with the specified title exists.

public bool HasTab(string title)

Parameters

title string

The title to search for.

Returns

bool

True if a tab with the title exists, false otherwise.

InsertTab(int, string, IWindowControl)

Inserts a new tab at the specified index.

public void InsertTab(int index, string title, IWindowControl content)

Parameters

index int

The index where the tab should be inserted.

title string

The title displayed in the tab header.

content IWindowControl

The control to display when this tab is active.

Invalidate(bool, IWindowControl?)

Marks this container as needing to be redrawn.

public void Invalidate(bool redrawAll, IWindowControl? callerControl = null)

Parameters

redrawAll bool

If true, forces a complete redraw of all content.

callerControl IWindowControl

The control that triggered the invalidation, if any.

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.

NextTab()

Switches to the next tab (wraps around to first tab).

public void NextTab()

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

PreviousTab()

Switches to the previous tab (wraps around to last tab).

public void PreviousTab()

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

RemoveTab(int)

Removes a tab at the specified index.

public void RemoveTab(int index)

Parameters

index int

The index of the tab to remove.

RemoveTab(string)

Removes the first tab with the specified title.

public bool RemoveTab(string title)

Parameters

title string

The title of the tab to remove.

Returns

bool

True if a tab was removed, false otherwise.

RemoveTabAt(int)

Removes a tab at the specified index.

public void RemoveTabAt(int index)

Parameters

index int

The index of the tab to remove.

SetTabContent(int, IWindowControl)

Sets the content of a tab at the specified index.

public void SetTabContent(int index, IWindowControl newContent)

Parameters

index int

The index of the tab.

newContent IWindowControl

The new content control.

SetTabTitle(int, string)

Sets the title of a tab at the specified index.

public void SetTabTitle(int index, string newTitle)

Parameters

index int

The index of the tab.

newTitle string

The new title.

SwitchToTab(string)

Switches to a tab by title.

public bool SwitchToTab(string title)

Parameters

title string

The title of the tab to switch to.

Returns

bool

True if the tab was found and switched to, false otherwise.

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

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

public event EventHandler<MouseEventArgs>? MouseRightClick

Event Type

EventHandler<MouseEventArgs>

TabAdded

Raised when a tab is added to the control.

public event EventHandler<TabEventArgs>? TabAdded

Event Type

EventHandler<TabEventArgs>

TabChanged

Raised after the active tab has changed.

public event EventHandler<TabChangedEventArgs>? TabChanged

Event Type

EventHandler<TabChangedEventArgs>

TabChanging

Raised before the active tab changes. Can be canceled.

public event EventHandler<TabChangingEventArgs>? TabChanging

Event Type

EventHandler<TabChangingEventArgs>

TabCloseRequested

Raised when the user clicks the close (×) button on a closable tab. The tab is NOT automatically removed — subscribe and call RemoveTab to close it.

public event EventHandler<TabEventArgs>? TabCloseRequested

Event Type

EventHandler<TabEventArgs>

TabRemoved

Raised when a tab is removed from the control.

public event EventHandler<TabEventArgs>? TabRemoved

Event Type

EventHandler<TabEventArgs>