Table of Contents

Class MultilineEditControl

Namespace
SharpConsoleUI.Controls
Assembly
SharpConsoleUI.dll

A multiline text editing control with support for text selection, scrolling, and word wrap. Provides full cursor navigation, cut/copy/paste-like operations, and configurable scrollbars.

public class MultilineEditControl : IInteractiveControl, IFocusableControl, IMouseAwareControl, IWindowControl, IDisposable, ILogicalCursorProvider, ICursorShapeProvider, IDOMPaintable
Inheritance
MultilineEditControl
Implements
Inherited Members
Extension Methods

Constructors

MultilineEditControl(int)

Initializes a new instance of the MultilineEditControl with the specified viewport height.

public MultilineEditControl(int viewportHeight = 10)

Parameters

viewportHeight int

The number of visible lines in the viewport.

MultilineEditControl(string, int)

Initializes a new instance of the MultilineEditControl with initial content and viewport height.

public MultilineEditControl(string initialContent, int viewportHeight = 10)

Parameters

initialContent string

The initial text content to display.

viewportHeight int

The number of visible lines in the viewport.

Properties

ActualWidth

Gets the actual rendered width of the control content in characters.

public int? ActualWidth { get; }

Property Value

int?

BackgroundColor

Gets or sets the background color when the control is not focused.

public Color BackgroundColor { get; set; }

Property Value

Color

BorderColor

Gets or sets the border color of the control.

public Color BorderColor { 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 IContainer? Container { get; set; }

Property Value

IContainer

Content

Gets or sets the text content as a single string with line breaks.

public string Content { get; set; }

Property Value

string

FocusedBackgroundColor

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

public Color FocusedBackgroundColor { get; set; }

Property Value

Color

FocusedForegroundColor

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

public Color FocusedForegroundColor { get; set; }

Property Value

Color

ForegroundColor

Gets or sets the foreground color when the control is not focused.

public Color ForegroundColor { get; set; }

Property Value

Color

HasFocus

Gets or sets whether this control currently has keyboard focus.

public bool HasFocus { get; set; }

Property Value

bool

HorizontalAlignment

Gets or sets the text alignment within the control.

public HorizontalAlignment HorizontalAlignment { get; set; }

Property Value

HorizontalAlignment

HorizontalScrollbarVisibility

Gets or sets when the horizontal scrollbar is displayed.

public ScrollbarVisibility HorizontalScrollbarVisibility { get; set; }

Property Value

ScrollbarVisibility

IsEditing

Gets or sets whether the control is currently in text editing mode.

public bool IsEditing { 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

Margin

Gets or sets the margin (spacing) around the control.

public Margin Margin { get; set; }

Property Value

Margin

Name

Gets or sets the unique name identifier for this control, used for lookup.

public string? Name { get; set; }

Property Value

string

PreferredCursorShape

Gets the preferred cursor shape based on editing state. Returns VerticalBar when editing (like modern text editors), null otherwise.

public CursorShape? PreferredCursorShape { get; }

Property Value

CursorShape?

ReadOnly

Gets or sets whether the control is in read-only mode. When read-only, users can navigate and select text, but cannot modify content.

public bool ReadOnly { get; set; }

Property Value

bool

ScrollbarColor

Gets or sets the scrollbar track color.

public Color ScrollbarColor { get; set; }

Property Value

Color

ScrollbarThumbColor

Gets or sets the scrollbar thumb (handle) color.

public Color ScrollbarThumbColor { get; set; }

Property Value

Color

SelectionBackgroundColor

Gets or sets the background color for selected text.

public Color SelectionBackgroundColor { get; set; }

Property Value

Color

SelectionForegroundColor

Gets or sets the foreground color for selected text.

public Color SelectionForegroundColor { get; set; }

Property Value

Color

StickyPosition

Gets or sets whether this control should stick to the top or bottom during scrolling.

public StickyPosition StickyPosition { get; set; }

Property Value

StickyPosition

Tag

Gets or sets an arbitrary object value that can be used to store custom data.

public object? Tag { get; set; }

Property Value

object

VerticalAlignment

Gets or sets the vertical alignment of the control within its container.

public VerticalAlignment VerticalAlignment { get; set; }

Property Value

VerticalAlignment

VerticalScrollbarVisibility

Gets or sets when the vertical scrollbar is displayed.

public ScrollbarVisibility VerticalScrollbarVisibility { get; set; }

Property Value

ScrollbarVisibility

ViewportHeight

Gets or sets the number of visible lines in the viewport.

public int ViewportHeight { get; set; }

Property Value

int

Visible

Gets or sets whether this control is visible.

public bool Visible { get; set; }

Property Value

bool

WantsMouseEvents

Whether this control wants to receive mouse events

public bool WantsMouseEvents { get; }

Property Value

bool

Width

Gets or sets the explicit width of the control, or null for automatic sizing.

public int? Width { get; set; }

Property Value

int?

WrapMode

Gets or sets the text wrapping mode.

public WrapMode WrapMode { get; set; }

Property Value

WrapMode

Methods

AppendContent(string)

Appends content to the end of the control and scrolls to make it visible.

public void AppendContent(string content)

Parameters

content string

The content to append.

AppendContentLines(List<string>)

Appends multiple lines to the end of the control and scrolls to make them visible.

public void AppendContentLines(List<string> lines)

Parameters

lines List<string>

The lines to append.

ClearSelection()

Clears the current text selection.

public void ClearSelection()

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

EnsureCursorVisible()

Ensures the cursor position is visible within the viewport by adjusting scroll offsets.

public void EnsureCursorVisible()

GetContent()

Gets the text content as a single string with line breaks.

public string GetContent()

Returns

string

The complete text content.

GetLogicalContentSize()

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

public Size GetLogicalContentSize()

Returns

Size

The size representing the content's natural dimensions.

GetLogicalCursorPosition()

Gets the logical cursor position within the control's content coordinate system. This should be the raw position without any visual adjustments for margins, scrolling, etc.

public Point? GetLogicalCursorPosition()

Returns

Point?

Logical cursor position or null if no cursor.

GetSelectedText()

Gets the currently selected text.

public string GetSelectedText()

Returns

string

The selected text, or an empty string if no selection exists.

GoToEnd()

Moves the cursor to the end of the document content and ensures it's visible.

public void GoToEnd()

InsertText(string)

Insert text at the current cursor position

public void InsertText(string text)

Parameters

text string

Invalidate()

Marks this control as needing to be re-rendered.

public void Invalidate()

MeasureDOM(LayoutConstraints)

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

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

SetContent(string)

Sets the text content from a string, splitting on line breaks.

public void SetContent(string content)

Parameters

content string

The text content to set.

SetContentLines(List<string>)

Sets the content of the control using a list of strings, with each string representing a line.

public void SetContentLines(List<string> lines)

Parameters

lines List<string>

The lines to set as content.

SetFocus(bool, FocusReason)

Sets focus to this control

public void SetFocus(bool focus, FocusReason reason = FocusReason.Programmatic)

Parameters

focus bool

Whether to give or remove focus

reason FocusReason

The reason for the focus change

SetLogicalCursorPosition(Point)

Sets the logical cursor position within the control's content coordinate system.

public void SetLogicalCursorPosition(Point position)

Parameters

position Point

Events

ContentChanged

Occurs when the text content changes.

public event EventHandler<string>? ContentChanged

Event Type

EventHandler<string>

GotFocus

Occurs when the control receives focus.

public event EventHandler? GotFocus

Event Type

EventHandler

LostFocus

Occurs when the control loses focus.

public event EventHandler? LostFocus

Event Type

EventHandler

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>