Class ControlHost
Adds the ability for a host to contain and display controls from SadConsole.UI.Controls.
Implements
Inherited Members
Namespace: SadConsole.UI
Assembly: SadConsole.dll
Syntax
public class ControlHost : IComponent, IContainer, IList<ControlBase>, ICollection<ControlBase>, IEnumerable<ControlBase>, IEnumerable
Constructors
ControlHost()
Declaration
public ControlHost()
Fields
ControlsList
The collection of controls.
Declaration
[DataMember]
protected List<ControlBase> ControlsList
Field Value
Type | Description |
---|---|
List<ControlBase> |
NamedControls
The controls added which contain a Name value.
Declaration
protected Dictionary<string, ControlBase> NamedControls
Field Value
Type | Description |
---|---|
Dictionary<string, ControlBase> |
Properties
CanTabToNextConsole
When true, allows the tab command to move to the next console (when there is a parent) instead of cycling back to the first control on this console.
Declaration
[DataMember]
public bool CanTabToNextConsole { get; set; }
Property Value
Type | Description |
---|---|
bool |
CapturedControl
Gets the control currently capturing mouse events.
Declaration
public ControlBase? CapturedControl { get; }
Property Value
Type | Description |
---|---|
ControlBase |
ClearOnAdded
When true, the component will clear the console it's attached to with the theme color.
Declaration
[DataMember]
public bool ClearOnAdded { get; set; }
Property Value
Type | Description |
---|---|
bool |
Count
The total number of controls in this component.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int |
DisableControlFocusing
When set to true, child controls are not alerted to focused and non-focused states.
Declaration
[DataMember]
public bool DisableControlFocusing { get; set; }
Property Value
Type | Description |
---|---|
bool |
DisableCursorOnAdded
When true, the component will disable the cursor of the console it's attached to.
Declaration
[DataMember]
public bool DisableCursorOnAdded { get; set; }
Property Value
Type | Description |
---|---|
bool |
FocusedControl
Gets or sets the control that has keyboard focus.
Declaration
public ControlBase? FocusedControl { get; set; }
Property Value
Type | Description |
---|---|
ControlBase |
IsDirty
Indicates that the control host needs to be redrawn.
Declaration
public bool IsDirty { get; set; }
Property Value
Type | Description |
---|---|
bool |
IsReadOnly
Always returns false.
Declaration
public bool IsReadOnly { get; }
Property Value
Type | Description |
---|---|
bool |
this[int]
Gets a control by index.
Declaration
public ControlBase this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of the control. |
Property Value
Type | Description |
---|---|
ControlBase | A control. |
this[string]
Gets a control by its Name property.
Declaration
public ControlBase this[string name] { get; }
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the control. |
Property Value
Type | Description |
---|---|
ControlBase | The control. |
NextTabConsole
Sets reference to the console to tab to when the CanTabToNextConsole property is true. Set this to null to allow the engine to determine the next console.
Declaration
public IScreenSurface? NextTabConsole { get; set; }
Property Value
Type | Description |
---|---|
IScreenSurface |
ParentConsole
The parent object hosting the controls.
Declaration
public IScreenSurface? ParentConsole { get; }
Property Value
Type | Description |
---|---|
IScreenSurface |
PreviousTabConsole
Sets reference to the console to tab to when the CanTabToNextConsole property is true. Set this to null to allow the engine to determine the next console.
Declaration
public IScreenSurface? PreviousTabConsole { get; set; }
Property Value
Type | Description |
---|---|
IScreenSurface |
SortOrder
Indicates priority to other components.
Declaration
public uint SortOrder { get; set; }
Property Value
Type | Description |
---|---|
uint |
ThemeColors
Gets or sets the colors to use with drawing the console and controls.
Declaration
public Colors? ThemeColors { get; set; }
Property Value
Type | Description |
---|---|
Colors |
Methods
Add(ControlBase)
Adds an existing control to this console.
Declaration
public void Add(ControlBase control)
Parameters
Type | Name | Description |
---|---|---|
ControlBase | control | The control to add. |
CanFocusControl(ControlBase?)
Declaration
protected virtual bool CanFocusControl(ControlBase? control)
Parameters
Type | Name | Description |
---|---|---|
ControlBase | control | The control to check. |
Returns
CaptureControl(ControlBase)
Captures a control for exclusive mouse focus. Sets the ExclusiveMouse property to true.
Declaration
public void CaptureControl(ControlBase control)
Parameters
Type | Name | Description |
---|---|---|
ControlBase | control | The control to capture |
Clear()
Removes all controls from this console.
Declaration
public void Clear()
Contains(ControlBase)
Checks if the specified control exists in this console.
Declaration
public bool Contains(ControlBase control)
Parameters
Type | Name | Description |
---|---|---|
ControlBase | control | The control to check. |
Returns
Type | Description |
---|---|
bool | True when the control exists in this console; otherwise false. |
CopyTo(ControlBase[], int)
Copies the controls to a new array.
Declaration
public void CopyTo(ControlBase[] array, int arrayIndex)
Parameters
Type | Name | Description |
---|---|---|
ControlBase[] | array | The destination array. |
int | arrayIndex | The starting index of where to copy the controls in the destination array. |
FocusedControlChanged(ControlBase?, ControlBase?)
This method actually changes the variable that tracks which control is focused. It then sets the IsFocused property to the appropriate value for both the previously focused control and the newly focused control.
Declaration
protected virtual void FocusedControlChanged(ControlBase? newControl, ControlBase? oldControl)
Parameters
Type | Name | Description |
---|---|---|
ControlBase | newControl | The control that should be focused. |
ControlBase | oldControl | The control that currently has focus. |
FocusedControlChanging(ControlBase?, ControlBase?)
When overridden, allows you to prevent a control from taking focus from another control.
Declaration
protected virtual bool FocusedControlChanging(ControlBase? newControl, ControlBase? oldControl)
Parameters
Type | Name | Description |
---|---|---|
ControlBase | newControl | The control requesting focus. |
ControlBase | oldControl | The control that has focus. |
Returns
ForceRedrawAllControls()
Forces each control to dirty so that the next frame will redraw each control.
Declaration
public void ForceRedrawAllControls()
GetEnumerator()
Gets an enumerator of the controls collection.
Declaration
public IEnumerator<ControlBase> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<ControlBase> | The enumerator of the controls collection. |
GetNamedControl(string)
Gets a control by its Name property.
Declaration
public ControlBase GetNamedControl(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the control. |
Returns
Type | Description |
---|---|
ControlBase | The control. |
GetThemeColors()
Returns the colors assigned to this console or the library default.
Declaration
public Colors GetThemeColors()
Returns
Type | Description |
---|---|
Colors | The found colors. |
HasNamedControl(string)
Checks whether or not the container has a control registered with the given name.
Declaration
public bool HasNamedControl(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name to check. |
Returns
HasNamedControl(string, out ControlBase?)
Checks whether or not the container has a control registered with the given name. If found, the instance is assigned to the control
parameter.
Declaration
public bool HasNamedControl(string name, out ControlBase? control)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name to check. |
ControlBase | control | The control instance found. |
Returns
IndexOf(ControlBase)
Gets the index of the specified control.
Declaration
public int IndexOf(ControlBase control)
Parameters
Type | Name | Description |
---|---|---|
ControlBase | control | The control. |
Returns
Type | Description |
---|---|
int | The index of the control in the backing collection. |
Insert(int, ControlBase)
Inserts an item at the specified index and sets the TabIndex to the specified index.
Declaration
public void Insert(int index, ControlBase control)
Parameters
Type | Name | Description |
---|---|---|
int | index | Index to insert at. |
ControlBase | control | The control to insert. |
Remarks
Index within the backing collection is always based on TabIndex ranking. There may be conflicts so you're not guaranteed that the control will be available at the specified index.
ReOrderControls()
Reorders the control collection based on the tab index of each control.
Declaration
public void ReOrderControls()
ReleaseControl()
Releases the control from exclusive mouse focus. Sets the ExclusiveMouse property to false and sets the CapturedControl property to null.
Declaration
public void ReleaseControl()
Remove(ControlBase)
Removes a control from this console.
Declaration
public bool Remove(ControlBase control)
Parameters
Type | Name | Description |
---|---|---|
ControlBase | control | The control to remove. |
Returns
Type | Description |
---|---|
bool | true if item was successfully removed; otherwise, false. This method also returns false if item is not found. |
RemoveAt(int)
Removes a control by index.
Declaration
public void RemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index |
TabNextControl()
Gives the focus to the next control in the tab order.
Declaration
public void TabNextControl()
TabPreviousControl()
Gives focus to the previous control in the tab order.
Declaration
public void TabPreviousControl()
ToArray()
Gets an array containing all of the controls this host contains.
Declaration
public ControlBase[] ToArray()
Returns
Type | Description |
---|---|
ControlBase[] |
TryTabNextConsole()
Tries to tab to the console that comes after this one in the Parent collection of Children. Sets focus to the target console if found.
Declaration
protected bool TryTabNextConsole()
Returns
TryTabPreviousConsole()
Tries to tab to the console that comes before this one in the Parent collection of Children. Sets focus to the target console if found.
Declaration
protected bool TryTabPreviousConsole()