Class TextBox
InputBox control that allows text input.
Inherited Members
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
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
OnUnfocused()
Called when the control loses focus.
Declaration
protected override void OnUnfocused()
Overrides
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
Resize(int, int)
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
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
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
Declaration
public event EventHandler<StringValidation.Result>? TextValidated
Event Type
| Type | Description |
|---|---|
| EventHandler<StringValidation.Result> |