Skip to content

ControlHost Class

Adds the ability for a host to contain and display controls from SadConsole.UI.Controls.

C#
public class ControlHost : IComponent, IContainer, IList<ControlBase>, ICollection<ControlBase>, IEnumerable<ControlBase>, IEnumerable

Inheritance object

Implements IComponent, IContainer, IList<ControlBase>, ICollection<ControlBase>, IEnumerable<ControlBase>, IEnumerable

C#
public ControlHost()

The collection of controls.

C#
[DataMember]
protected List<ControlBase> ControlsList

The controls added which contain a Name value.

C#
protected Dictionary<string, ControlBase> NamedControls

Indicates priority to other components.

C#
public uint SortOrder { get; set; }

Gets a control by index.

C#
public ControlBase this[int index] { get; }

The parent object hosting the controls.

C#
public IScreenSurface? ParentConsole { get; }

Gets or sets the colors to use with drawing the console and controls.

C#
public Colors? ThemeColors { get; set; }

Indicates that the control host needs to be redrawn.

C#
public bool IsDirty { get; set; }

Gets the control currently capturing mouse events.

C#
public ControlBase? CapturedControl { get; }

Gets or sets the control that has keyboard focus.

C#
public ControlBase? FocusedControl { get; set; }

When true, the component will clear the console it’s attached to with the theme color.

C#
[DataMember]
public bool ClearOnAdded { get; set; }

When true, the component will disable the cursor of the console it’s attached to.

C#
[DataMember]
public bool DisableCursorOnAdded { get; set; }

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.

C#
[DataMember]
public bool CanTabToNextConsole { get; set; }

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.

C#
public IScreenSurface? NextTabConsole { get; set; }

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.

C#
public IScreenSurface? PreviousTabConsole { get; set; }

When set to true, child controls are not alerted to focused and non-focused states.

C#
[DataMember]
public bool DisableControlFocusing { get; set; }

The total number of controls in this component.

C#
public int Count { get; }

Always returns false.

C#
public bool IsReadOnly { get; }

Gets a control by its Name property.

C#
public ControlBase this[string name] { get; }

Checks whether or not the container has a control registered with the given name.

C#
public bool HasNamedControl(string name)

name string
The name to check.

bool
true when the control is found; otherwise false.

Checks whether or not the container has a control registered with the given name. If found, the instance is assigned to the control parameter.

C#
public bool HasNamedControl(string name, out ControlBase? control)

name string
The name to check.

control ControlBase
The control instance found.

bool
true when the control is found; otherwise false.

Gets a control by its Name property.

C#
public ControlBase GetNamedControl(string name)

name string
The name of the control.

ControlBase
The control.

Gives the focus to the next control in the tab order.

C#
public void TabNextControl()

Gives focus to the previous control in the tab order.

C#
public void TabPreviousControl()

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.

C#
protected bool TryTabPreviousConsole()

bool
true if the tab was successful; otherwise, false.

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.

C#
protected bool TryTabNextConsole()

bool
true if the tab was successful; otherwise, false.

Returns the colors assigned to this console or the library default.

C#
public Colors GetThemeColors()

Colors
The found colors.

Gets an array containing all of the controls this host contains.

C#
public ControlBase[] ToArray()

ControlBase[]

FocusedControlChanging(ControlBase?, ControlBase?)

Section titled “FocusedControlChanging(ControlBase?, ControlBase?)”

When overridden, allows you to prevent a control from taking focus from another control.

C#
protected virtual bool FocusedControlChanging(ControlBase? newControl, ControlBase? oldControl)

newControl ControlBase
The control requesting focus.

oldControl ControlBase
The control that has focus.

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.

C#
protected virtual void FocusedControlChanged(ControlBase? newControl, ControlBase? oldControl)

newControl ControlBase
The control that should be focused.

oldControl ControlBase
The control that currently has focus.

Determins if a control is enabled and CanFocus is true.

C#
protected virtual bool CanFocusControl(ControlBase? control)

control ControlBase
The control to check.

bool
true when the control can be focused; otherwise false.

Reorders the control collection based on the tab index of each control.

C#
public void ReOrderControls()

Captures a control for exclusive mouse focus. Sets the ExclusiveMouse property to true.

C#
public void CaptureControl(ControlBase control)

control ControlBase
The control to capture

Releases the control from exclusive mouse focus. Sets the ExclusiveMouse property to false and sets the CapturedControl property to null.

C#
public void ReleaseControl()

Forces each control to dirty so that the next frame will redraw each control.

C#
public void ForceRedrawAllControls()

Gets an enumerator of the controls collection.

C#
public IEnumerator<ControlBase> GetEnumerator()

IEnumerator<ControlBase>
The enumerator of the controls collection.

Gets the index of the specified control.

C#
public int IndexOf(ControlBase control)

control ControlBase
The control.

int
The index of the control in the backing collection.

Inserts an item at the specified index and sets the TabIndex to the specified index.

C#
public void Insert(int index, ControlBase control)

index int
Index to insert at.

control ControlBase
The control to insert.

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.

Removes a control by index.

C#
public void RemoveAt(int index)

index int

Adds an existing control to this console.

C#
public void Add(ControlBase control)

control ControlBase
The control to add.

Removes all controls from this console.

C#
public void Clear()

Checks if the specified control exists in this console.

C#
public bool Contains(ControlBase control)

control ControlBase
The control to check.

bool
True when the control exists in this console; otherwise false.

Copies the controls to a new array.

C#
public void CopyTo(ControlBase[] array, int arrayIndex)

array ControlBase[]
The destination array.

arrayIndex int
The starting index of where to copy the controls in the destination array.

Removes a control from this console.

C#
public bool Remove(ControlBase control)

control ControlBase
The control to remove.

bool
true if item was successfully removed; otherwise, false. This method also returns false if item is not found.