Class TextField
Single-line text entry View
Inherited Members
Namespace: Terminal.Gui
Assembly: Terminal.Gui.dll
Syntax
public class TextField : View, IDisposable, ISupportInitializeNotification, ISupportInitialize
Remarks
Constructors
| Edit this page View SourceTextField()
Declaration
public TextField()
TextField(ustring)
Declaration
public TextField(ustring text)
Parameters
| Type | Name | Description |
|---|---|---|
| ustring | text | Initial text contents. |
TextField(int, int, int, ustring)
Declaration
public TextField(int x, int y, int w, ustring text)
Parameters
| Type | Name | Description |
|---|---|---|
| int | x | The x coordinate. |
| int | y | The y coordinate. |
| int | w | The width. |
| ustring | text | Initial text contents. |
TextField(string)
Declaration
public TextField(string text)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | Initial text contents. |
Properties
| Edit this page View SourceAutocomplete
Provides autocomplete context menu based on suggestions at the current cursor
position. Populate AllSuggestions to enable this feature.
Declaration
public IAutocomplete Autocomplete { get; protected set; }
Property Value
| Type | Description |
|---|---|
| IAutocomplete |
CanFocus
Gets or sets a value indicating whether this Responder can focus.
Declaration
public override bool CanFocus { get; set; }
Property Value
| Type | Description |
|---|---|
| bool | true if can focus; otherwise, false. |
Overrides
| Edit this page View SourceContextMenu
Get the ContextMenu for this view.
Declaration
public ContextMenu ContextMenu { get; }
Property Value
| Type | Description |
|---|---|
| ContextMenu |
CursorPosition
Sets or gets the current cursor position.
Declaration
public virtual int CursorPosition { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
DesiredCursorVisibility
Get / Set the wished cursor when the field is focused
Declaration
public CursorVisibility DesiredCursorVisibility { get; set; }
Property Value
| Type | Description |
|---|---|
| CursorVisibility |
Frame
Gets or sets the frame for the view. The frame is relative to the view's container (SuperView).
Declaration
public override Rect Frame { get; set; }
Property Value
| Type | Description |
|---|---|
| Rect | The frame. |
Overrides
Remarks
Change the Frame when using the Absolute layout style to move or resize views.
Altering the Frame of a view will trigger the redrawing of the view as well as the redrawing of the affected regions of the SuperView.
HasHistoryChanges
Indicates whatever the text has history changes or not.
true if the text has history changes false otherwise.
Declaration
public bool HasHistoryChanges { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsDirty
Declaration
public bool IsDirty { get; }
Property Value
| Type | Description |
|---|---|
| bool |
ReadOnly
If set to true its not allow any changes in the text.
Declaration
public bool ReadOnly { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
ScrollOffset
Gets the left offset position.
Declaration
public int ScrollOffset { get; }
Property Value
| Type | Description |
|---|---|
| int |
Secret
Sets the secret property.
Declaration
public bool Secret { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
This makes the text entry suitable for entering passwords.
|
Edit this page
View Source
SelectedLength
Length of the selected text.
Declaration
public int SelectedLength { get; }
Property Value
| Type | Description |
|---|---|
| int |
SelectedStart
Start position of the selected text.
Declaration
public int SelectedStart { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
SelectedText
The selected text.
Declaration
public ustring SelectedText { get; }
Property Value
| Type | Description |
|---|---|
| ustring |
Text
Sets or gets the text held by the view.
Declaration
public ustring Text { get; set; }
Property Value
| Type | Description |
|---|---|
| ustring |
Used
Tracks whether the text field should be considered "used", that is, that the user has moved in the entry, so new input should be appended at the cursor position, rather than clearing the entry
Declaration
public bool Used { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
| Edit this page View SourceClearAllSelection()
Clear the selected text.
Declaration
public void ClearAllSelection()
ClearHistoryChanges()
Allows clearing the HistoryText.HistoryTextItem items updating the original text.
Declaration
public void ClearHistoryChanges()
Copy()
Copy the selected text to the clipboard.
Declaration
public virtual void Copy()
Cut()
Cut the selected text to the clipboard.
Declaration
public virtual void Cut()
DeleteAll()
Deletes all text.
Declaration
public void DeleteAll()
DeleteCharLeft(bool)
Deletes the left character.
Declaration
public virtual void DeleteCharLeft(bool useOldCursorPos = true)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | useOldCursorPos |
DeleteCharRight()
Deletes the right character.
Declaration
public virtual void DeleteCharRight()
GetNormalColor()
Determines the current ColorScheme based on the Enabled value.
Declaration
public override Attribute GetNormalColor()
Returns
| Type | Description |
|---|---|
| Attribute | Normal if Enabled is true or Disabled if Enabled is false. If it's overridden can return other values. |
Overrides
| Edit this page View SourceInsertText(string, bool)
Inserts the given
toAdd text at the current cursor position
exactly as if the user had just typed itDeclaration
public void InsertText(string toAdd, bool useOldCursorPos = true)
Parameters
| Type | Name | Description |
|---|---|---|
| string | toAdd | Text to add |
| bool | useOldCursorPos | If uses the oldCursorPos. |
KillWordBackwards()
Deletes word backwards.
Declaration
public virtual void KillWordBackwards()
KillWordForwards()
Deletes word forwards.
Declaration
public virtual void KillWordForwards()
MouseEvent(MouseEvent)
Method invoked when a mouse event is generated
Declaration
public override bool MouseEvent(MouseEvent ev)
Parameters
| Type | Name | Description |
|---|---|---|
| MouseEvent | ev |
Returns
| Type | Description |
|---|---|
| bool | true, if the event was handled, false otherwise. |
Overrides
| Edit this page View SourceOnEnter(View)
Method invoked when a view gets focus.
Declaration
public override bool OnEnter(View view)
Parameters
| Type | Name | Description |
|---|---|---|
| View | view | The view that is losing focus. |
Returns
| Type | Description |
|---|---|
| bool | true, if the event was handled, false otherwise. |
Overrides
| Edit this page View SourceOnLeave(View)
Method invoked when a view loses focus.
Declaration
public override bool OnLeave(View view)
Parameters
| Type | Name | Description |
|---|---|---|
| View | view | The view that is getting focus. |
Returns
| Type | Description |
|---|---|
| bool | true, if the event was handled, false otherwise. |
Overrides
| Edit this page View SourceOnTextChanging(ustring)
Virtual method that invoke the TextChanging event if it's defined.
Declaration
public virtual TextChangingEventArgs OnTextChanging(ustring newText)
Parameters
| Type | Name | Description |
|---|---|---|
| ustring | newText | The new text to be replaced. |
Returns
| Type | Description |
|---|---|
| TextChangingEventArgs | Returns the TextChangingEventArgs |
Paste()
Paste the selected text from the clipboard.
Declaration
public virtual void Paste()
PositionCursor()
Sets the cursor position.
Declaration
public override void PositionCursor()
Overrides
| Edit this page View SourceProcessKey(KeyEvent)
Processes key presses for the TextField.
Declaration
public override bool ProcessKey(KeyEvent kb)
Parameters
| Type | Name | Description |
|---|---|---|
| KeyEvent | kb |
Returns
| Type | Description |
|---|---|
| bool |
Overrides
Remarks
The TextField control responds to the following keys:
|
Edit this page
View Source
| Keys | Function |
|---|---|
| Delete, Backspace | Deletes the character before cursor. |
Redraw(Rect)
Redraws this view and its subviews; only redraws the views that have been flagged for a re-display.
Declaration
public override void Redraw(Rect bounds)
Parameters
| Type | Name | Description |
|---|---|---|
| Rect | bounds | The bounds (view-relative region) to redraw. |
Overrides
Remarks
Always use Bounds (view-relative) when calling Redraw(Rect), NOT Frame (superview-relative).
Views should set the color that they want to use on entry, as otherwise this will inherit the last color that was set globally on the driver.
Overrides of Redraw(Rect) must ensure they do not set Driver.Clip to a clip region
larger than the parameter, as this will cause the driver to clip the entire region.
SelectAll()
Selects all text.
Declaration
public void SelectAll()
Events
| Edit this page View SourceTextChanged
Changed event, raised when the text has changed.
Declaration
public event Action<ustring> TextChanged
Event Type
| Type | Description |
|---|---|
| Action<ustring> |
Remarks
This event is raised when the Text changes.
|
Edit this page
View Source
TextChanging
Changing event, raised before the Text changes and can be canceled or changing the new text.
Declaration
public event Action<TextChangingEventArgs> TextChanging
Event Type
| Type | Description |
|---|---|
| Action<TextChangingEventArgs> |