ControlHost Class
Definition
Section titled “Definition”Adds the ability for a host to contain and display controls from SadConsole.UI.Controls.
public class ControlHost : IComponent, IContainer, IList<ControlBase>, ICollection<ControlBase>, IEnumerable<ControlBase>, IEnumerableInheritance object
Implements IComponent, IContainer, IList<ControlBase>, ICollection<ControlBase>, IEnumerable<ControlBase>, IEnumerable
Constructors
Section titled “Constructors”ControlHost()
Section titled “ControlHost()”public ControlHost()Fields
Section titled “Fields”ControlsList
Section titled “ControlsList”The collection of controls.
[DataMember]protected List<ControlBase> ControlsListNamedControls
Section titled “NamedControls”The controls added which contain a Name value.
protected Dictionary<string, ControlBase> NamedControlsProperties
Section titled “Properties”SortOrder
Section titled “SortOrder”Indicates priority to other components.
public uint SortOrder { get; set; }this[int]
Section titled “this[int]”Gets a control by index.
public ControlBase this[int index] { get; }ParentConsole
Section titled “ParentConsole”The parent object hosting the controls.
public IScreenSurface? ParentConsole { get; }ThemeColors
Section titled “ThemeColors”Gets or sets the colors to use with drawing the console and controls.
public Colors? ThemeColors { get; set; }IsDirty
Section titled “IsDirty”Indicates that the control host needs to be redrawn.
public bool IsDirty { get; set; }CapturedControl
Section titled “CapturedControl”Gets the control currently capturing mouse events.
public ControlBase? CapturedControl { get; }FocusedControl
Section titled “FocusedControl”Gets or sets the control that has keyboard focus.
public ControlBase? FocusedControl { get; set; }ClearOnAdded
Section titled “ClearOnAdded”When true, the component will clear the console it’s attached to with the theme color.
[DataMember]public bool ClearOnAdded { get; set; }DisableCursorOnAdded
Section titled “DisableCursorOnAdded”When true, the component will disable the cursor of the console it’s attached to.
[DataMember]public bool DisableCursorOnAdded { get; set; }CanTabToNextConsole
Section titled “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.
[DataMember]public bool CanTabToNextConsole { get; set; }NextTabConsole
Section titled “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.
public IScreenSurface? NextTabConsole { get; set; }PreviousTabConsole
Section titled “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.
public IScreenSurface? PreviousTabConsole { get; set; }DisableControlFocusing
Section titled “DisableControlFocusing”When set to true, child controls are not alerted to focused and non-focused states.
[DataMember]public bool DisableControlFocusing { get; set; }The total number of controls in this component.
public int Count { get; }IsReadOnly
Section titled “IsReadOnly”Always returns false.
public bool IsReadOnly { get; }this[string]
Section titled “this[string]”Gets a control by its Name property.
public ControlBase this[string name] { get; }Methods
Section titled “Methods”HasNamedControl(string)
Section titled “HasNamedControl(string)”Checks whether or not the container has a control registered with the given name.
public bool HasNamedControl(string name)Parameters
Section titled “Parameters”name string
The name to check.
Returns
Section titled “Returns”bool
true when the control is found; otherwise false.
HasNamedControl(string, out ControlBase?)
Section titled “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.
public bool HasNamedControl(string name, out ControlBase? control)Parameters
Section titled “Parameters”name string
The name to check.
control ControlBase
The control instance found.
Returns
Section titled “Returns”bool
true when the control is found; otherwise false.
GetNamedControl(string)
Section titled “GetNamedControl(string)”Gets a control by its Name property.
public ControlBase GetNamedControl(string name)Parameters
Section titled “Parameters”name string
The name of the control.
Returns
Section titled “Returns”ControlBase
The control.
TabNextControl()
Section titled “TabNextControl()”Gives the focus to the next control in the tab order.
public void TabNextControl()TabPreviousControl()
Section titled “TabPreviousControl()”Gives focus to the previous control in the tab order.
public void TabPreviousControl()TryTabPreviousConsole()
Section titled “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.
protected bool TryTabPreviousConsole()Returns
Section titled “Returns”bool
true if the tab was successful; otherwise, false.
TryTabNextConsole()
Section titled “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.
protected bool TryTabNextConsole()Returns
Section titled “Returns”bool
true if the tab was successful; otherwise, false.
GetThemeColors()
Section titled “GetThemeColors()”Returns the colors assigned to this console or the library default.
public Colors GetThemeColors()Returns
Section titled “Returns”Colors
The found colors.
ToArray()
Section titled “ToArray()”Gets an array containing all of the controls this host contains.
public ControlBase[] ToArray()Returns
Section titled “Returns”FocusedControlChanging(ControlBase?, ControlBase?)
Section titled “FocusedControlChanging(ControlBase?, ControlBase?)”When overridden, allows you to prevent a control from taking focus from another control.
protected virtual bool FocusedControlChanging(ControlBase? newControl, ControlBase? oldControl)Parameters
Section titled “Parameters”newControl ControlBase
The control requesting focus.
oldControl ControlBase
The control that has focus.
Returns
Section titled “Returns”bool
true when the focus change is allowed; otherwise false.
FocusedControlChanged(ControlBase?, ControlBase?)
Section titled “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.
protected virtual void FocusedControlChanged(ControlBase? newControl, ControlBase? oldControl)Parameters
Section titled “Parameters”newControl ControlBase
The control that should be focused.
oldControl ControlBase
The control that currently has focus.
CanFocusControl(ControlBase?)
Section titled “CanFocusControl(ControlBase?)”Determins if a control is enabled and CanFocus is true.
protected virtual bool CanFocusControl(ControlBase? control)Parameters
Section titled “Parameters”control ControlBase
The control to check.
Returns
Section titled “Returns”bool
true when the control can be focused; otherwise false.
ReOrderControls()
Section titled “ReOrderControls()”Reorders the control collection based on the tab index of each control.
public void ReOrderControls()CaptureControl(ControlBase)
Section titled “CaptureControl(ControlBase)”Captures a control for exclusive mouse focus. Sets the ExclusiveMouse property to true.
public void CaptureControl(ControlBase control)Parameters
Section titled “Parameters”control ControlBase
The control to capture
ReleaseControl()
Section titled “ReleaseControl()”Releases the control from exclusive mouse focus. Sets the ExclusiveMouse property to false and sets the CapturedControl property to null.
public void ReleaseControl()ForceRedrawAllControls()
Section titled “ForceRedrawAllControls()”Forces each control to dirty so that the next frame will redraw each control.
public void ForceRedrawAllControls()GetEnumerator()
Section titled “GetEnumerator()”Gets an enumerator of the controls collection.
public IEnumerator<ControlBase> GetEnumerator()Returns
Section titled “Returns”IEnumerator<ControlBase>
The enumerator of the controls collection.
IndexOf(ControlBase)
Section titled “IndexOf(ControlBase)”Gets the index of the specified control.
public int IndexOf(ControlBase control)Parameters
Section titled “Parameters”control ControlBase
The control.
Returns
Section titled “Returns”int
The index of the control in the backing collection.
Insert(int, ControlBase)
Section titled “Insert(int, ControlBase)”Inserts an item at the specified index and sets the TabIndex to the specified index.
public void Insert(int index, ControlBase control)Parameters
Section titled “Parameters”index int
Index to insert at.
control ControlBase
The control to insert.
Remarks
Section titled “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.
RemoveAt(int)
Section titled “RemoveAt(int)”Removes a control by index.
public void RemoveAt(int index)Parameters
Section titled “Parameters”index int
Add(ControlBase)
Section titled “Add(ControlBase)”Adds an existing control to this console.
public void Add(ControlBase control)Parameters
Section titled “Parameters”control ControlBase
The control to add.
Clear()
Section titled “Clear()”Removes all controls from this console.
public void Clear()Contains(ControlBase)
Section titled “Contains(ControlBase)”Checks if the specified control exists in this console.
public bool Contains(ControlBase control)Parameters
Section titled “Parameters”control ControlBase
The control to check.
Returns
Section titled “Returns”bool
True when the control exists in this console; otherwise false.
CopyTo(ControlBase[], int)
Section titled “CopyTo(ControlBase[], int)”Copies the controls to a new array.
public void CopyTo(ControlBase[] array, int arrayIndex)Parameters
Section titled “Parameters”array ControlBase[]
The destination array.
arrayIndex int
The starting index of where to copy the controls in the destination array.
Remove(ControlBase)
Section titled “Remove(ControlBase)”Removes a control from this console.
public bool Remove(ControlBase control)Parameters
Section titled “Parameters”control ControlBase
The control to remove.
Returns
Section titled “Returns”bool
true if item was successfully removed; otherwise, false. This method also returns false if item is not found.