Class View
View is the base class for all views on the screen and represents a visible element that can render itself and contains zero or more nested views.
Inheritance
System.Object
View
Implements
System.IDisposable
System.ComponentModel.ISupportInitializeNotification
System.ComponentModel.ISupportInitialize
Inherited Members
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)
Assembly: Terminal.Gui.dll
Syntax
public class View : Responder, IDisposable, ISupportInitializeNotification, ISupportInitialize
Constructors
View()
Declaration
View(ustring, TextDirection, Border)
Declaration
public View(ustring text, TextDirection direction = TextDirection.LeftRight_TopBottom, Border border = null)
Parameters
Type |
Name |
Description |
NStack.ustring |
text |
text to initialize the Text property with. |
TextDirection |
direction |
The text direction. |
Border |
border |
The Border. |
View(Int32, Int32, ustring)
Declaration
public View(int x, int y, ustring text)
Parameters
Type |
Name |
Description |
System.Int32 |
x |
column to locate the Label. |
System.Int32 |
y |
row to locate the Label. |
NStack.ustring |
text |
text to initialize the Text property with. |
View(Rect)
Initializes a new instance of a
Absolute View class with the absolute
dimensions specified in the
frame
parameter.
Declaration
Parameters
Type |
Name |
Description |
Rect |
frame |
The region covered by this view. |
View(Rect, ustring, Border)
Declaration
public View(Rect rect, ustring text, Border border = null)
Parameters
Type |
Name |
Description |
Rect |
rect |
Location. |
NStack.ustring |
text |
text to initialize the Text property with. |
Border |
border |
The Border. |
Properties
AutoSize
Declaration
public virtual bool AutoSize { get; set; }
Property Value
Type |
Description |
System.Boolean |
|
Border
Declaration
public virtual Border Border { get; set; }
Property Value
Bounds
The bounds represent the View-relative rectangle used for this view; the area inside of the view.
Declaration
public Rect Bounds { get; set; }
Property Value
Type |
Description |
Rect |
The bounds. |
CanFocus
Declaration
public override bool CanFocus { get; set; }
Property Value
Type |
Description |
System.Boolean |
|
Overrides
ColorScheme
The color scheme for this view, if it is not defined, it returns the
SuperView's
color scheme.
Declaration
public ColorScheme ColorScheme { get; set; }
Property Value
Data
Gets or sets arbitrary data for the view.
Declaration
public object Data { get; set; }
Property Value
Type |
Description |
System.Object |
|
Driver
Points to the current driver in use by the view, it is a convenience property
for simplifying the development of new views.
Declaration
public static ConsoleDriver Driver { get; }
Property Value
Enabled
Declaration
public override bool Enabled { get; set; }
Property Value
Type |
Description |
System.Boolean |
|
Overrides
Focused
Returns the currently focused view inside this view, or null if nothing is focused.
Declaration
public View Focused { get; }
Property Value
Type |
Description |
View |
The focused. |
Frame
Gets or sets the frame for the view. The frame is relative to the view's container (
SuperView).
Declaration
public virtual Rect Frame { get; set; }
Property Value
Type |
Description |
Rect |
The frame. |
HasFocus
Declaration
public override bool HasFocus { get; }
Property Value
Type |
Description |
System.Boolean |
|
Overrides
Height
Declaration
public Dim Height { get; set; }
Property Value
Type |
Description |
Dim |
The height. |
HotKey
Gets or sets the HotKey defined for this view. A user pressing HotKey on the keyboard while this view has focus will cause the Clicked event to fire.
Declaration
public Key HotKey { get; set; }
Property Value
HotKeySpecifier
Gets or sets the specifier character for the hotkey (e.g. '_'). Set to '\xffff' to disable hotkey support for this View instance. The default is '\xffff'.
Declaration
public Rune HotKeySpecifier { get; set; }
Property Value
Type |
Description |
System.Rune |
|
Id
Gets or sets an identifier for the view;
Declaration
public ustring Id { get; set; }
Property Value
Type |
Description |
NStack.ustring |
The identifier. |
IsCurrentTop
Returns a value indicating if this View is currently on Top (Active)
Declaration
public bool IsCurrentTop { get; }
Property Value
Type |
Description |
System.Boolean |
|
IsInitialized
Get or sets if the
View was already initialized.
This derived from
System.ComponentModel.ISupportInitializeNotification to allow notify all the views that are being initialized.
Declaration
public virtual bool IsInitialized { get; set; }
Property Value
Type |
Description |
System.Boolean |
|
LayoutStyle
Controls how the View's
Frame is computed during the LayoutSubviews method, if the style is set to
Absolute,
LayoutSubviews does not change the
Frame. If the style is
Computed the
Frame is updated using
the
X,
Y,
Width, and
Height properties.
Declaration
public LayoutStyle LayoutStyle { get; set; }
Property Value
MostFocused
Returns the most focused view in the chain of subviews (the leaf view that has the focus).
Declaration
public View MostFocused { get; }
Property Value
Type |
Description |
View |
The most focused. |
Shortcut
This is the global setting that can be used as a global shortcut to invoke an action if provided.
Declaration
public Key Shortcut { get; set; }
Property Value
ShortcutAction
The action to run if the
Shortcut is defined.
Declaration
public virtual Action ShortcutAction { get; set; }
Property Value
Type |
Description |
System.Action |
|
ShortcutTag
The keystroke combination used in the
Shortcut as string.
Declaration
public ustring ShortcutTag { get; }
Property Value
Type |
Description |
NStack.ustring |
|
Subviews
This returns a list of the subviews contained by this view.
Declaration
public IList<View> Subviews { get; }
Property Value
Type |
Description |
System.Collections.Generic.IList<View> |
The subviews. |
SuperView
Returns the container for this view, or null if this view has not been added to a container.
Declaration
public View SuperView { get; }
Property Value
Type |
Description |
View |
The super view. |
TabIndex
Declaration
public int TabIndex { get; set; }
Property Value
Type |
Description |
System.Int32 |
|
TabIndexes
This returns a tab index list of the subviews contained by this view.
Declaration
public IList<View> TabIndexes { get; }
Property Value
Type |
Description |
System.Collections.Generic.IList<View> |
The tabIndexes. |
TabStop
This only be
true
if the
CanFocus is also
true
and the focus can be avoided by setting this to
false
Declaration
public bool TabStop { get; set; }
Property Value
Type |
Description |
System.Boolean |
|
Text
The text displayed by the
View.
Declaration
public virtual ustring Text { get; set; }
Property Value
Type |
Description |
NStack.ustring |
|
TextAlignment
Gets or sets how the View's
Text is aligned horizontally when drawn. Changing this property will redisplay the
View.
Declaration
public virtual TextAlignment TextAlignment { get; set; }
Property Value
TextDirection
Gets or sets the direction of the View's
Text. Changing this property will redisplay the
View.
Declaration
public virtual TextDirection TextDirection { get; set; }
Property Value
VerticalTextAlignment
Gets or sets how the View's
Text is aligned verticaly when drawn. Changing this property will redisplay the
View.
Declaration
public virtual VerticalTextAlignment VerticalTextAlignment { get; set; }
Property Value
Visible
Declaration
public override bool Visible { get; set; }
Property Value
Type |
Description |
System.Boolean |
|
Overrides
Gets or sets a value indicating whether this
View want continuous button pressed event.
Declaration
public virtual bool WantContinuousButtonPressed { get; set; }
Property Value
Type |
Description |
System.Boolean |
|
WantMousePositionReports
Gets or sets a value indicating whether this
View wants mouse position reports.
Declaration
public virtual bool WantMousePositionReports { get; set; }
Property Value
Type |
Description |
System.Boolean |
true if want mouse position reports; otherwise, false . |
Width
Declaration
public Dim Width { get; set; }
Property Value
Type |
Description |
Dim |
The width. |
X
Declaration
public Pos X { get; set; }
Property Value
Type |
Description |
Pos |
The X Position. |
Y
Declaration
public Pos Y { get; set; }
Property Value
Type |
Description |
Pos |
The y position (line). |
Methods
Add(View)
Adds a subview (child) to this view.
Declaration
public virtual void Add(View view)
Parameters
Type |
Name |
Description |
View |
view |
|
Add(View[])
Adds the specified views (children) to the view.
Declaration
public void Add(params View[] views)
Parameters
Type |
Name |
Description |
View[] |
views |
Array of one or more views (can be optional parameter). |
AddRune(Int32, Int32, Rune)
Displays the specified character in the specified column and row of the View.
Declaration
public void AddRune(int col, int row, Rune ch)
Parameters
Type |
Name |
Description |
System.Int32 |
col |
Column (view-relative). |
System.Int32 |
row |
Row (view-relative). |
System.Rune |
ch |
Ch. |
BeginInit()
This derived from System.ComponentModel.ISupportInitializeNotification to allow notify all the views that are beginning initialized.
Declaration
BringSubviewForward(View)
Moves the subview backwards in the hierarchy, only one step
Declaration
public void BringSubviewForward(View subview)
Parameters
Type |
Name |
Description |
View |
subview |
The subview to send backwards |
BringSubviewToFront(View)
Brings the specified subview to the front so it is drawn on top of any other views.
Declaration
public void BringSubviewToFront(View subview)
Parameters
Type |
Name |
Description |
View |
subview |
The subview to send to the front |
Clear()
Clears the view region with the current color.
Declaration
Clear(Rect)
Clears the specified region with the current color.
Declaration
public void Clear(Rect regionScreen)
Parameters
Type |
Name |
Description |
Rect |
regionScreen |
The screen-relative region to clear. |
ClearLayoutNeeded()
Removes the Terminal.Gui.View.SetNeedsLayout setting on this view.
Declaration
protected void ClearLayoutNeeded()
ClearNeedsDisplay()
Removes the
SetNeedsDisplay() and the
Terminal.Gui.View.ChildNeedsDisplay setting on this view.
Declaration
protected void ClearNeedsDisplay()
ClipToBounds()
Declaration
public Rect ClipToBounds()
Returns
Type |
Description |
Rect |
The existing driver's clip region, which can be then re-applied by setting Driver.Clip (Clip). |
Dispose(Boolean)
Declaration
protected override void Dispose(bool disposing)
Parameters
Type |
Name |
Description |
System.Boolean |
disposing |
|
Overrides
DrawFrame(Rect, Int32, Boolean)
Draws a frame in the current view, clipped by the boundary of this view
Declaration
public void DrawFrame(Rect region, int padding = 0, bool fill = false)
Parameters
Type |
Name |
Description |
Rect |
region |
View-relative region for the frame to be drawn. |
System.Int32 |
padding |
The padding to add around the outside of the drawn frame. |
System.Boolean |
fill |
If set to true it fill will the contents. |
DrawHotString(ustring, Boolean, ColorScheme)
Utility function to draw strings that contains a hotkey using a
ColorScheme and the "focused" state.
Declaration
public void DrawHotString(ustring text, bool focused, ColorScheme scheme)
Parameters
Type |
Name |
Description |
NStack.ustring |
text |
String to display, the underscore before a letter flags the next letter as the hotkey. |
System.Boolean |
focused |
If set to true this uses the focused colors from the color scheme, otherwise the regular ones. |
ColorScheme |
scheme |
The color scheme to use. |
DrawHotString(ustring, Attribute, Attribute)
Utility function to draw strings that contain a hotkey.
Declaration
public void DrawHotString(ustring text, Attribute hotColor, Attribute normalColor)
Parameters
Type |
Name |
Description |
NStack.ustring |
text |
String to display, the hotkey specifier before a letter flags the next letter as the hotkey. |
Attribute |
hotColor |
Hot color. |
Attribute |
normalColor |
Normal color. |
EndInit()
This derived from System.ComponentModel.ISupportInitializeNotification to allow notify all the views that are ending initialized.
Declaration
EnsureFocus()
Finds the first view in the hierarchy that wants to get the focus if nothing is currently focused, otherwise, it does nothing.
Declaration
public void EnsureFocus()
FocusFirst()
Focuses the first focusable subview if one exists.
Declaration
FocusLast()
Focuses the last focusable subview if one exists.
Declaration
FocusNext()
Focuses the next view.
Declaration
Returns
Type |
Description |
System.Boolean |
true , if next was focused, false otherwise. |
FocusPrev()
Focuses the previous view.
Declaration
Returns
Type |
Description |
System.Boolean |
true , if previous was focused, false otherwise. |
GetCurrentHeight(out Int32)
Calculate the height based on the
Height settings.
Declaration
public bool GetCurrentHeight(out int currentHeight)
Parameters
Type |
Name |
Description |
System.Int32 |
currentHeight |
The real current height. |
Returns
Type |
Description |
System.Boolean |
true if the height can be directly assigned, false otherwise. |
GetCurrentWidth(out Int32)
Gets the current width based on the
Width settings.
Declaration
public bool GetCurrentWidth(out int currentWidth)
Parameters
Type |
Name |
Description |
System.Int32 |
currentWidth |
The real current width. |
Returns
Type |
Description |
System.Boolean |
true if the width can be directly assigned, false otherwise. |
GetNormalColor()
Declaration
public Attribute GetNormalColor()
Returns
LayoutSubviews()
Invoked when a view starts executing or when the dimensions of the view have changed, for example in
response to the container view or terminal resizing.
Declaration
public virtual void LayoutSubviews()
Move(Int32, Int32)
This moves the cursor to the specified column and row in the view.
Declaration
public void Move(int col, int row)
Parameters
Type |
Name |
Description |
System.Int32 |
col |
Col. |
System.Int32 |
row |
Row. |
OnAdded(View)
Method invoked when a subview is being added to this view.
Declaration
public virtual void OnAdded(View view)
Parameters
Type |
Name |
Description |
View |
view |
The subview being added. |
OnCanFocusChanged()
Declaration
public override void OnCanFocusChanged()
Overrides
OnDrawContent(Rect)
Enables overrides to draw infinitely scrolled content and/or a background behind added controls.
Declaration
public virtual void OnDrawContent(Rect viewport)
Parameters
Type |
Name |
Description |
Rect |
viewport |
The view-relative rectangle describing the currently visible viewport into the View |
OnEnabledChanged()
Declaration
public override void OnEnabledChanged()
Overrides
OnEnter(View)
Declaration
public override bool OnEnter(View view)
Parameters
Type |
Name |
Description |
View |
view |
|
Returns
Type |
Description |
System.Boolean |
|
Overrides
OnKeyDown(KeyEvent)
Declaration
public override bool OnKeyDown(KeyEvent keyEvent)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Overrides
OnKeyUp(KeyEvent)
Declaration
public override bool OnKeyUp(KeyEvent keyEvent)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Overrides
OnLeave(View)
Declaration
public override bool OnLeave(View view)
Parameters
Type |
Name |
Description |
View |
view |
|
Returns
Type |
Description |
System.Boolean |
|
Overrides
OnMouseClick(View.MouseEventArgs)
Invokes the MouseClick event.
Declaration
protected bool OnMouseClick(View.MouseEventArgs args)
Parameters
Returns
Type |
Description |
System.Boolean |
|
OnMouseEnter(MouseEvent)
Declaration
public override bool OnMouseEnter(MouseEvent mouseEvent)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Overrides
OnMouseEvent(MouseEvent)
Method invoked when a mouse event is generated
Declaration
public virtual bool OnMouseEvent(MouseEvent mouseEvent)
Parameters
Returns
Type |
Description |
System.Boolean |
true , if the event was handled, false otherwise. |
OnMouseLeave(MouseEvent)
Declaration
public override bool OnMouseLeave(MouseEvent mouseEvent)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Overrides
OnRemoved(View)
Method invoked when a subview is being removed from this view.
Declaration
public virtual void OnRemoved(View view)
Parameters
Type |
Name |
Description |
View |
view |
The subview being removed. |
OnVisibleChanged()
Declaration
public override void OnVisibleChanged()
Overrides
PositionCursor()
Positions the cursor in the right position based on the currently focused view in the chain.
Declaration
public virtual void PositionCursor()
ProcessColdKey(KeyEvent)
Declaration
public override bool ProcessColdKey(KeyEvent keyEvent)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Overrides
ProcessHotKey(KeyEvent)
Declaration
public override bool ProcessHotKey(KeyEvent keyEvent)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Overrides
ProcessKey(KeyEvent)
Declaration
public override bool ProcessKey(KeyEvent keyEvent)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Overrides
Redraw(Rect)
Redraws this view and its subviews; only redraws the views that have been flagged for a re-display.
Declaration
public virtual void Redraw(Rect bounds)
Parameters
Type |
Name |
Description |
Rect |
bounds |
The bounds (view-relative region) to redraw. |
Remove(View)
Declaration
public virtual void Remove(View view)
Parameters
Type |
Name |
Description |
View |
view |
|
RemoveAll()
Declaration
public virtual void RemoveAll()
ScreenToView(Int32, Int32)
Converts a point from screen-relative coordinates to view-relative coordinates.
Declaration
public Point ScreenToView(int x, int y)
Parameters
Type |
Name |
Description |
System.Int32 |
x |
X screen-coordinate point. |
System.Int32 |
y |
Y screen-coordinate point. |
Returns
Type |
Description |
Point |
The mapped point. |
SendSubviewBackwards(View)
Moves the subview backwards in the hierarchy, only one step
Declaration
public void SendSubviewBackwards(View subview)
Parameters
Type |
Name |
Description |
View |
subview |
The subview to send backwards |
SendSubviewToBack(View)
Sends the specified subview to the front so it is the first view drawn
Declaration
public void SendSubviewToBack(View subview)
Parameters
Type |
Name |
Description |
View |
subview |
The subview to send to the front |
SetChildNeedsDisplay()
Indicates that any child views (in the
Subviews list) need to be repainted.
Declaration
public void SetChildNeedsDisplay()
SetClip(Rect)
Sets the clip region to the specified view-relative region.
Declaration
public Rect SetClip(Rect region)
Parameters
Type |
Name |
Description |
Rect |
region |
View-relative clip region. |
Returns
Type |
Description |
Rect |
The previous screen-relative clip region. |
SetFocus()
Causes the specified view and the entire parent hierarchy to have the focused order updated.
Declaration
SetHeight(Int32, out Int32)
Calculate the height based on the
Height settings.
Declaration
public bool SetHeight(int desiredHeight, out int resultHeight)
Parameters
Type |
Name |
Description |
System.Int32 |
desiredHeight |
The desired height. |
System.Int32 |
resultHeight |
The real result height. |
Returns
Type |
Description |
System.Boolean |
true if the height can be directly assigned, false otherwise. |
SetNeedsDisplay()
Sets a flag indicating this view needs to be redisplayed because its state has changed.
Declaration
public void SetNeedsDisplay()
SetNeedsDisplay(Rect)
Flags the view-relative region on this View as needing to be repainted.
Declaration
public void SetNeedsDisplay(Rect region)
Parameters
Type |
Name |
Description |
Rect |
region |
The view-relative region that must be flagged for repaint. |
SetWidth(Int32, out Int32)
Calculate the width based on the
Width settings.
Declaration
public bool SetWidth(int desiredWidth, out int resultWidth)
Parameters
Type |
Name |
Description |
System.Int32 |
desiredWidth |
The desired width. |
System.Int32 |
resultWidth |
The real result width. |
Returns
Type |
Description |
System.Boolean |
true if the width can be directly assigned, false otherwise. |
ToString()
Pretty prints the View
Declaration
public override string ToString()
Returns
Type |
Description |
System.String |
|
Overrides
System.Object.ToString()
Events
Added
Event fired when a subview is being added to this view.
Declaration
public event Action<View> Added
Event Type
Type |
Description |
System.Action<View> |
|
CanFocusChanged
Event fired when the
CanFocus value is being changed.
Declaration
public event Action CanFocusChanged
Event Type
Type |
Description |
System.Action |
|
DrawContent
Event invoked when the content area of the View is to be drawn.
Declaration
public event Action<Rect> DrawContent
Event Type
Type |
Description |
System.Action<Rect> |
|
EnabledChanged
Event fired when the
Enabled value is being changed.
Declaration
public event Action EnabledChanged
Event Type
Type |
Description |
System.Action |
|
Enter
Event fired when the view gets focus.
Declaration
public event Action<View.FocusEventArgs> Enter
Event Type
Initialized
Event called only once when the
View is being initialized for the first time.
Allows configurations and assignments to be performed before the
View being shown.
This derived from
System.ComponentModel.ISupportInitializeNotification to allow notify all the views that are being initialized.
Declaration
public event EventHandler Initialized
Event Type
Type |
Description |
System.EventHandler |
|
KeyDown
Invoked when a key is pressed
Declaration
public event Action<View.KeyEventEventArgs> KeyDown
Event Type
KeyPress
Invoked when a character key is pressed and occurs after the key up event.
Declaration
public event Action<View.KeyEventEventArgs> KeyPress
Event Type
KeyUp
Invoked when a key is released
Declaration
public event Action<View.KeyEventEventArgs> KeyUp
Event Type
LayoutComplete
Declaration
public event Action<View.LayoutEventArgs> LayoutComplete
Event Type
LayoutStarted
Declaration
public event Action<View.LayoutEventArgs> LayoutStarted
Event Type
Leave
Event fired when the view looses focus.
Declaration
public event Action<View.FocusEventArgs> Leave
Event Type
MouseClick
Event fired when a mouse event is generated.
Declaration
public event Action<View.MouseEventArgs> MouseClick
Event Type
MouseEnter
Event fired when the view receives the mouse event for the first time.
Declaration
public event Action<View.MouseEventArgs> MouseEnter
Event Type
MouseLeave
Event fired when the view receives a mouse event for the last time.
Declaration
public event Action<View.MouseEventArgs> MouseLeave
Event Type
Removed
Event fired when a subview is being removed from this view.
Declaration
public event Action<View> Removed
Event Type
Type |
Description |
System.Action<View> |
|
VisibleChanged
Event fired when the
Visible value is being changed.
Declaration
public event Action VisibleChanged
Event Type
Type |
Description |
System.Action |
|
Implements
System.IDisposable
System.ComponentModel.ISupportInitializeNotification
System.ComponentModel.ISupportInitialize