Show / Hide Table of Contents

Class TextBox

InputBox control that allows text input.

Inheritance
object
ControlBase
TextBox
NumberBox
Inherited Members
ControlBase.MouseState_IsMouseOver
ControlBase.MouseState_EnteredWithButtonDown
ControlBase.MouseState_IsMouseLeftDown
ControlBase.MouseState_IsMouseRightDown
ControlBase.OnIsDirtyChanged()
ControlBase.ProcessMouse(MouseScreenObjectState)
ControlBase.LostMouse(MouseScreenObjectState)
ControlBase.OnParentChanged()
ControlBase.OnPositionChanged()
ControlBase.PlaceRelativeTo(ControlBase, Direction.Types, int)
ControlBase.DetermineState()
ControlBase.OnStateChanged(ControlStates, ControlStates)
ControlBase.OnSurfaceChanged(ICellSurface, ICellSurface)
ControlBase.FindThemeFont()
ControlBase.FindThemeColors()
ControlBase.SetThemeColors(Colors)
ControlBase.HasThemeColors()
ControlBase.OnResized()
ControlBase.CreateControlSurface()
ControlBase.RefreshThemeStateColors(Colors)
ControlBase.OnMouseEnter(ControlBase.ControlMouseState)
ControlBase.OnMouseExit(ControlBase.ControlMouseState)
ControlBase.OnMouseIn(ControlBase.ControlMouseState)
ControlBase.OnRightMouseClicked(ControlBase.ControlMouseState)
ControlBase.ThemeState
ControlBase.UseKeyboard
ControlBase.UseMouse
ControlBase.CanFocus
ControlBase.CanResize
ControlBase.AlternateFont
ControlBase.Surface
ControlBase.MouseArea
ControlBase.IsMouseButtonStateClean
ControlBase.Position
ControlBase.AbsolutePosition
ControlBase.IsVisible
ControlBase.Tag
ControlBase.TabStop
ControlBase.TabIndex
ControlBase.IsDirty
ControlBase.Name
ControlBase.FocusOnMouseClick
ControlBase.Width
ControlBase.Height
ControlBase.IsFocused
ControlBase.IsEnabled
ControlBase.Bounds
ControlBase.Parent
ControlBase.State
ControlBase.IsDirtyChanged
ControlBase.Focused
ControlBase.Unfocused
ControlBase.PositionChanged
ControlBase.MouseEnter
ControlBase.MouseExit
ControlBase.MouseMove
ControlBase.MouseButtonClicked
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: SadConsole.UI.Controls
Assembly: SadConsole.dll
Syntax
[DataContract]
public class TextBox : ControlBase

Constructors

TextBox(int)

Creates a new instance of the input box.

Declaration
public TextBox(int width)
Parameters
Type Name Description
int width

The width of the input box.

Fields

_cachedBuilder

String builder used while processing text in the ProcessKeyboard(Keyboard) method.

Declaration
protected StringBuilder? _cachedBuilder
Field Value
Type Description
StringBuilder

_caretPos

The location of the caret.

Declaration
protected int _caretPos
Field Value
Type Description
int

_text

The text value of the input box.

Declaration
[DataMember(Name = "Text")]
protected string _text
Field Value
Type Description
string

Properties

CaretEffect

The style to use for the carrot.

Declaration
[DataMember]
public ICellEffect CaretEffect { get; set; }
Property Value
Type Description
ICellEffect

CaretPosition

Gets or sets the position of the caret in the current text.

Declaration
public int CaretPosition { get; set; }
Property Value
Type Description
int

DisableKeyboard

Disables the keyboard which turns off keyboard input and hides the cursor.

Declaration
[DataMember(Name = "DisableKeyboardInput")]
public bool DisableKeyboard { get; set; }
Property Value
Type Description
bool

DisableMouse

Disables mouse input.

Declaration
[DataMember(Name = "DisableMouseInput")]
public bool DisableMouse { get; set; }
Property Value
Type Description
bool

LeftDrawOffset

When editing the text box, this allows the text to scroll to the right so you can see what you are typing.

Declaration
public int LeftDrawOffset { get; protected set; }
Property Value
Type Description
int

Mask

Mask input with a certain character.

Declaration
public char? Mask { get; set; }
Property Value
Type Description
char?

MaxLength

How big the text can be. Setting this to 0 will make it unlimited.

Declaration
[DataMember]
public int MaxLength { get; set; }
Property Value
Type Description
int

Text

Gets or sets the text of the input box.

Declaration
public string Text { get; set; }
Property Value
Type Description
string

TextAreaWidth

The width to display the text area at when UseDifferentTextAreaWidth is true.

Declaration
public int TextAreaWidth { get; set; }
Property Value
Type Description
int

UseDifferentTextAreaWidth

Enables displaying the text area at a different width than the width of the control.

Declaration
public bool UseDifferentTextAreaWidth { get; set; }
Property Value
Type Description
bool

Validator

When set, validates the Text property after TextChangedPreview has allowed the result.

Declaration
public StringValidation.Validator? Validator { get; set; }
Property Value
Type Description
StringValidation.Validator

Methods

CheckKeyPressCancel(AsciiKey)

Raises the KeyPressed event and returns true if the keypress was cancelled.

Declaration
protected bool CheckKeyPressCancel(AsciiKey key)
Parameters
Type Name Description
AsciiKey key

The key to use with the event.

Returns
Type Description
bool

true to indicate that the keypress should be considered cancelled.

OnFocused()

Called when the control is focused.

Declaration
protected override void OnFocused()
Overrides
ControlBase.OnFocused()

OnLeftMouseClicked(ControlMouseState)

Focuses the control and enters typing mode.

Declaration
protected override void OnLeftMouseClicked(ControlBase.ControlMouseState state)
Parameters
Type Name Description
ControlBase.ControlMouseState state

The mouse state.

Overrides
ControlBase.OnLeftMouseClicked(ControlBase.ControlMouseState)

OnUnfocused()

Called when the control loses focus.

Declaration
protected override void OnUnfocused()
Overrides
ControlBase.OnUnfocused()

ProcessKeyboard(Keyboard)

Called when the control should process keyboard information.

Declaration
public override bool ProcessKeyboard(Keyboard info)
Parameters
Type Name Description
Keyboard info

The keyboard information.

Returns
Type Description
bool

True if the keyboard was handled by this control.

Overrides
ControlBase.ProcessKeyboard(Keyboard)

Resize(int, int)

Resizes the control if the CanResize property is true.

Declaration
public override void Resize(int width, int height)
Parameters
Type Name Description
int width

The desired width of the control.

int height

The desired height of the control.

Overrides
ControlBase.Resize(int, int)

UpdateAndRedraw(TimeSpan)

Redraws the control if applicable.

Declaration
public override void UpdateAndRedraw(TimeSpan time)
Parameters
Type Name Description
TimeSpan time

The duration of thecurrent frame.

Overrides
ControlBase.UpdateAndRedraw(TimeSpan)

ValidateCursorPosition(string)

Correctly positions the cursor within the text.

Declaration
protected void ValidateCursorPosition(string text)
Parameters
Type Name Description
string text

Events

KeyPressed

Raised when a key is pressed on the textbox.

Declaration
public event EventHandler<KeyPressEventArgs>? KeyPressed
Event Type
Type Description
EventHandler<KeyPressEventArgs>

TextChanged

Raised when the text has changed and the preview has accepted it.

Declaration
public event EventHandler? TextChanged
Event Type
Type Description
EventHandler

TextChangedPreview

Raised before the text has changed and allows the change to be cancelled.

Declaration
public event EventHandler<ValueChangedCancelableEventArgs<string>>? TextChangedPreview
Event Type
Type Description
EventHandler<ValueChangedCancelableEventArgs<string>>

TextValidated

Raised when the Validator validates the Text property.

Declaration
public event EventHandler<StringValidation.Result>? TextValidated
Event Type
Type Description
EventHandler<StringValidation.Result>

Extension Methods

ExtensionsSystem.GetDebuggerDisplayValue(object)
In this article

Back to top

Back to top Generated by DocFX