Show / Hide Table of Contents

# Class TextView

Multi-line text editing View

##### Inheritance

System.Object
Responder
View
TextView

##### Implements

System.Collections.IEnumerable

##### Inherited Members

View.Enter
View.Leave
View.MouseEnter
View.MouseLeave
View.MouseClick
View.Driver
View.Subviews
View.Id
View.IsCurrentTop
View.WantMousePositionReports
View.WantContinuousButtonPressed
View.Frame
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.OnEnter()
View.OnLeave()
View.Focused
View.MostFocused
View.ColorScheme
View.AddRune(Int32, Int32, Rune)
View.ClearNeedsDisplay()
View.DrawContent
View.OnDrawContent(Rect)
View.SetFocus(View)
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.LayoutComplete
View.LayoutSubviews()
View.ToString()
View.OnMouseEnter(MouseEvent)
View.OnMouseLeave(MouseEvent)
View.OnMouseEvent(MouseEvent)
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 TextView : View, IEnumerable

##### Remarks

TextView provides a multi-line text editor. Users interact with it with the standard Emacs commands for movement or the arrow keys.

Shortcut | Action performed
--- | ---
Left cursor, Control-b | Moves the editing point left.
Right cursor, Control-f | Moves the editing point right.
Alt-b | Moves one word back.
Alt-f | Moves one word forward.
Up cursor, Control-p | Moves the editing point one line up.
Down cursor, Control-n | Moves the editing point one line down
Home key, Control-a | Moves the cursor to the beginning of the line.
End key, Control-e | Moves the cursor to the end of the line.
Delete, Control-d | Deletes the character in front of the cursor.
Backspace | Deletes the character behind the cursor.
Control-k | Deletes the text until the end of the line and replaces the kill buffer with the deleted text. You can paste this text in a different place by using Control-y.
Control-y | Pastes the content of the kill ring into the current position.
Alt-d | Deletes the word above the cursor and adds it to the kill ring. You can paste the contents of the kill ring with Control-y.
Control-q | Quotes the next input character, to prevent the normal processing of key handling to take place.

### Constructors

#### TextView()

Initalizes a TextView on the specified area, with dimensions controlled with the X, Y, Width and Height properties.

##### Declaration

    public TextView()

#### TextView(Rect)

Initalizes a TextView on the specified area, with absolute position and size.

##### Declaration

    public TextView(Rect frame)

##### Parameters

Type | Name | Description
--- | --- | ---
Rect | frame |

##### Remarks

### Fields

#### TextChanged

Raised when the Text of the TextView changes.

##### Declaration

    public Action TextChanged

##### Field Value

Type | Description
--- | ---
System.Action |

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

Responder.CanFocus

#### CurrentColumn

Gets the cursor column.

##### Declaration

    public int CurrentColumn { get; }

##### Property Value

Type | Description
--- | ---
System.Int32 | The cursor column.

#### CurrentRow

Gets the current cursor row.

##### Declaration

    public int CurrentRow { get; }

##### Property Value

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

#### ReadOnly

Gets or sets whether the TextView is in read-only mode or not

##### Declaration

    public bool ReadOnly { get; set; }

##### Property Value

Type | Description
--- | ---
System.Boolean | Boolean value(Default false)

#### Text

Sets or gets the text in the TextView.

##### Declaration

    public ustring Text { get; set; }

##### Property Value

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

##### Remarks

### Methods

#### CloseFile()

Closes the contents of the stream into the TextView.

##### Declaration

    public bool CloseFile()

##### Returns

Type | Description
--- | ---
System.Boolean | `true`, if stream was closed, `false` otherwise.

#### LoadFile(String)

Loads the contents of the file into the TextView.

##### Declaration

    public bool LoadFile(string path)

##### Parameters

Type | Name | Description
--- | --- | ---
System.String | path | Path to the file to load.

##### Returns

Type | Description
--- | ---
System.Boolean | `true`, if file was loaded, `false` otherwise.

#### LoadStream(Stream)

Loads the contents of the stream into the TextView.

##### Declaration

    public void LoadStream(Stream stream)

##### Parameters

Type | Name | Description
--- | --- | ---
System.IO.Stream | stream | Stream to load the contents from.

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

#### PositionCursor()

Positions the cursor on the current row and column

##### Declaration

    public override void PositionCursor()

##### Overrides

View.PositionCursor()

#### ProcessKey(KeyEvent)

If the view is focused, gives the view a chance to process the keystroke.

##### Declaration

    public override bool ProcessKey(KeyEvent kb)

##### Parameters

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

##### Returns

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

##### Overrides

View.ProcessKey(KeyEvent)

##### Remarks

Views can override this method if they are interested in processing the given keystroke. If they consume the keystroke, they must return true to stop the keystroke from being processed by other widgets or consumed by the widget engine. If they return false, the keystroke will be passed using the ProcessColdKey method to other views to process.

The View implementation does nothing but return false, so it is not necessary to call base.ProcessKey if you derive directly from View, but you should if you derive other View subclasses.

#### 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 globaly on the driver.

Overrides of Redraw(Rect) must ensure they do not set `Driver.Clip` to a clip region larger than the `region` parameter.

#### ScrollTo(Int32)

Will scroll the TextView to display the specified row at the top

##### Declaration

    public void ScrollTo(int row)

##### Parameters

Type | Name | Description
--- | --- | ---
System.Int32 | row | Row that should be displayed at the top, if the value is negative it will be reset to zero

### Implements

System.Collections.IEnumerable