Show / Hide Table of Contents

# Class TextField

Single-line text entry View

##### Inheritance

System.Object
Responder
View
TextField
DateField
TimeField

##### Implements

System.IDisposable
System.Collections.IEnumerable
System.ComponentModel.ISupportInitializeNotification
System.ComponentModel.ISupportInitialize

##### Inherited Members

View.Added
View.Removed
View.Enter
View.Leave
View.MouseEnter
View.MouseLeave
View.MouseClick
View.HotKey
View.HotKeySpecifier
View.Driver
View.Subviews
View.TabIndexes
View.TabIndex
View.TabStop
View.Id
View.IsCurrentTop
View.WantMousePositionReports
View.WantContinuousButtonPressed
View.GetEnumerator()
View.LayoutStyle
View.Bounds
View.X
View.Y
View.Width
View.Height
View.SuperView
View.SetNeedsDisplay()
View.SetNeedsDisplay(Rect)
View.ChildNeedsDisplay()
View.Add(View)
View.Add(View[])
View.RemoveAll()
View.Remove(View)
View.BringSubviewToFront(View)
View.SendSubviewToBack(View)
View.SendSubviewBackwards(View)
View.BringSubviewForward(View)
View.Clear()
View.Clear(Rect)
View.ScreenToView(Int32, Int32)
View.ClipToBounds()
View.SetClip(Rect)
View.DrawFrame(Rect, Int32, Boolean)
View.DrawHotString(ustring, Attribute, Attribute)
View.DrawHotString(ustring, Boolean, ColorScheme)
View.Move(Int32, Int32)
View.HasFocus
View.OnAdded(View)
View.OnRemoved(View)
View.OnEnter(View)
View.Focused
View.MostFocused
View.ColorScheme
View.AddRune(Int32, Int32, Rune)
View.ClearNeedsDisplay()
View.DrawContent
View.OnDrawContent(Rect)
View.SetFocus()
View.KeyPress
View.ProcessHotKey(KeyEvent)
View.ProcessColdKey(KeyEvent)
View.KeyDown
View.OnKeyDown(KeyEvent)
View.KeyUp
View.OnKeyUp(KeyEvent)
View.EnsureFocus()
View.FocusFirst()
View.FocusLast()
View.FocusPrev()
View.FocusNext()
View.LayoutStarted
View.LayoutComplete
View.Initialized
View.LayoutSubviews()
View.TextAlignment
View.IsInitialized
View.ToString()
View.OnMouseEnter(MouseEvent)
View.OnMouseLeave(MouseEvent)
View.OnMouseEvent(MouseEvent)
View.Dispose(Boolean)
View.BeginInit()
View.EndInit()
View.Visible
Responder.Dispose()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)

###### Namespace: Terminal.Gui

###### Assembly: Terminal.Gui.dll

##### Syntax

    public class TextField : View, IDisposable, IEnumerable, ISupportInitializeNotification, ISupportInitialize

##### Remarks

The TextField View provides editing functionality and mouse support.

### Constructors

#### TextField()

Initializes a new instance of the TextField class using Computed positioning.

##### Declaration

    public TextField()

#### TextField(ustring)

Initializes a new instance of the TextField class using Computed positioning.

##### Declaration

    public TextField(ustring text)

##### Parameters

Type | Name | Description
--- | --- | ---
NStack.ustring | text | Initial text contents.

#### TextField(Int32, Int32, Int32, ustring)

Initializes a new instance of the TextField class using Absolute positioning.

##### Declaration

    public TextField(int x, int y, int w, ustring text)

##### Parameters

Type | Name | Description
--- | --- | ---
System.Int32 | x | The x coordinate.
System.Int32 | y | The y coordinate.
System.Int32 | w | The width.
NStack.ustring | text | Initial text contents.

#### TextField(String)

Initializes a new instance of the TextField class using Computed positioning.

##### Declaration

    public TextField(string text)

##### Parameters

Type | Name | Description
--- | --- | ---
System.String | text | Initial text contents.

### Fields

#### TextChanged

Changed event, raised when the text has changed.

##### Declaration

    public Action<ustring> TextChanged

##### Field Value

Type | Description
--- | ---
System.Action<NStack.ustring> |

##### Remarks

This event is raised when the Text changes.

### Properties

#### CanFocus

Gets or sets a value indicating whether this Responder can focus.

##### Declaration

    public override bool CanFocus { get; set; }

##### Property Value

Type | Description
--- | ---
System.Boolean | `true` if can focus; otherwise, `false`.

##### Overrides

View.CanFocus

#### CursorPosition

Sets or gets the current cursor position.

##### Declaration

    public int CursorPosition { get; set; }

##### Property Value

Type | Description
--- | ---
System.Int32 |

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

View.Frame

##### 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.

#### ReadOnly

If set to true its not allow any changes in the text.

##### Declaration

    public bool ReadOnly { get; set; }

##### Property Value

Type | Description
--- | ---
System.Boolean |

#### Secret

Sets the secret property.

##### Declaration

    public bool Secret { get; set; }

##### Property Value

Type | Description
--- | ---
System.Boolean |

##### Remarks

This makes the text entry suitable for entering passwords.

#### SelectedLength

Length of the selected text.

##### Declaration

    public int SelectedLength { get; set; }

##### Property Value

Type | Description
--- | ---
System.Int32 |

#### SelectedStart

Start position of the selected text.

##### Declaration

    public int SelectedStart { get; set; }

##### Property Value

Type | Description
--- | ---
System.Int32 |

#### SelectedText

The selected text.

##### Declaration

    public ustring SelectedText { get; set; }

##### Property Value

Type | Description
--- | ---
NStack.ustring |

#### Text

Sets or gets the text held by the view.

##### Declaration

    public ustring Text { get; set; }

##### Property Value

Type | Description
--- | ---
NStack.ustring |

##### Remarks

#### 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
--- | ---
System.Boolean |

### Methods

#### ClearAllSelection()

Clear the selected text.

##### Declaration

    public void ClearAllSelection()

#### 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()

#### 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
--- | ---
System.Boolean | `true`, if the event was handled, `false` otherwise.

##### Overrides

Responder.MouseEvent(MouseEvent)

#### OnLeave(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
--- | ---
System.Boolean | `true`, if the event was handled, `false` otherwise.

##### Overrides

View.OnLeave(View)

#### Paste()

Paste the selected text from the clipboard.

##### Declaration

    public virtual void Paste()

#### PositionCursor()

Sets the cursor position.

##### Declaration

    public override void PositionCursor()

##### Overrides

View.PositionCursor()

#### ProcessKey(KeyEvent)

Processes key presses for the TextField.

##### Declaration

    public override bool ProcessKey(KeyEvent kb)

##### Parameters

Type | Name | Description
--- | --- | ---
KeyEvent | kb |

##### Returns

Type | Description
--- | ---
System.Boolean |

##### Overrides

View.ProcessKey(KeyEvent)

##### Remarks

The TextField control responds to the following keys:

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

View.Redraw(Rect)

##### 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 `region` parameter.

### Implements

System.IDisposable
System.Collections.IEnumerable
System.ComponentModel.ISupportInitializeNotification
System.ComponentModel.ISupportInitialize