ListBox Class
Definition
Section titled “Definition”A scrollable list control.
[DataContract]public class ListBox : CompositeControl, IContainer, IList<ControlBase>, ICollection<ControlBase>, IEnumerable<ControlBase>, IEnumerableInheritance object → ControlBase → CompositeControl
Implements IContainer, IList<ControlBase>, ICollection<ControlBase>, IEnumerable<ControlBase>, IEnumerable
Constructors
Section titled “Constructors”ListBox(int, int)
Section titled “ListBox(int, int)”Creates a new instance of the listbox control with the default theme for the items.
public ListBox(int width, int height)Parameters
Section titled “Parameters”width int
The width of the listbox.
height int
The height of the listbox.
ListBox(int, int, ListBoxItemTheme)
Section titled “ListBox(int, int, ListBoxItemTheme)”Creates a new instance of the listbox control with the specified item theme.
public ListBox(int width, int height, ListBoxItemTheme itemTheme)Parameters
Section titled “Parameters”width int
The width of the listbox.
height int
The height of the listbox.
itemTheme ListBoxItemTheme
The theme to use with rendering the listbox items.
Fields
Section titled “Fields”_reconfigureScrollBar
Section titled “_reconfigureScrollBar”Internal flag to indicate the scroll bar needs to be reconfigured.
protected bool _reconfigureScrollBarProperties
Section titled “Properties”IsScrollBarVisible
Section titled “IsScrollBarVisible”Internal use only; used in rendering.
public bool IsScrollBarVisible { get; set; }ScrollBar
Section titled “ScrollBar”The scroll bar control used with this list box.
[DataMember(Name = "ScrollBar")]public ScrollBar ScrollBar { get; protected set; }ItemIndexMouseOver
Section titled “ItemIndexMouseOver”Used in rendering.
public int ItemIndexMouseOver { get; }VisibleItemsTotal
Section titled “VisibleItemsTotal”The total items visible in the listbox.
public int VisibleItemsTotal { get; set; }VisibleItemsMax
Section titled “VisibleItemsMax”The maximum amount of items that can be shown in the listbox.
public int VisibleItemsMax { get; set; }CompareByReference
Section titled “CompareByReference”When the SelectedItem changes, and this property is true, objects will be compared by reference. If false, they will be compared by value.
[DataMember]public bool CompareByReference { get; set; }SingleClickItemExecute
Section titled “SingleClickItemExecute”When set to true, the SelectedItemExecuted event will fire when an item is single-clicked instead of double-clicked.
[DataMember]public bool SingleClickItemExecute { get; set; }The items in the listbox.
[DataMember]public ObservableCollection<object> Items { get; }SelectedIndex
Section titled “SelectedIndex”Gets or sets the index of the selected item.
public int SelectedIndex { get; set; }SelectedItem
Section titled “SelectedItem”Gets or sets the selected item.
public object? SelectedItem { get; set; }BorderTheme
Section titled “BorderTheme”The drawing theme for the border when DrawBorder is true.
public ThemeStates BorderTheme { get; protected set; }BorderLineStyle
Section titled “BorderLineStyle”The line style for the border when DrawBorder is true.
[DataMember]public int[] BorderLineStyle { get; set; }DrawBorder
Section titled “DrawBorder”If false the border will not be drawn.
[DataMember]public bool DrawBorder { get; set; }ItemTheme
Section titled “ItemTheme”The appearance of the items displayed by the listbox control.
[DataMember]public ListBoxItemTheme ItemTheme { get; set; }ItemsArea
Section titled “ItemsArea”The area on the control where items are drawn.
public Rectangle ItemsArea { get; set; }Methods
Section titled “Methods”OnSelectedItemChanged()
Section titled “OnSelectedItemChanged()”Invokes the SelectedItemChanged event.
protected virtual void OnSelectedItemChanged()OnItemAction()
Section titled “OnItemAction()”Invokes the SelectedItemExecuted event.
protected virtual void OnItemAction()OnResized()
Section titled “OnResized()”Called when Resize(int, int) was called.
protected override void OnResized()SetupScrollBar(Orientation, int, Point)
Section titled “SetupScrollBar(Orientation, int, Point)”Configures the associated ScrollBar.
public void SetupScrollBar(Orientation orientation, int sizeValue, Point position)Parameters
Section titled “Parameters”orientation Orientation
The orientation of the scrollbar.
sizeValue int
The size of the scrollbar.
position SadRogue.Primitives.Point
The position of the scrollbar.
ScrollToSelectedItem()
Section titled “ScrollToSelectedItem()”Scrolls the list to the item currently selected.
public void ScrollToSelectedItem()ProcessKeyboard(Keyboard)
Section titled “ProcessKeyboard(Keyboard)”Called when the keyboard is used on this control.
public override bool ProcessKeyboard(Keyboard info)Parameters
Section titled “Parameters”info Keyboard
Returns
Section titled “Returns”OnMouseIn(ControlMouseState)
Section titled “OnMouseIn(ControlMouseState)”Called as the mouse moves around the control area. Raises the MouseMove event and calls the DetermineState() method.
protected override void OnMouseIn(ControlBase.ControlMouseState state)Parameters
Section titled “Parameters”state ControlBase.ControlMouseState
The current mouse data
OnLeftMouseClicked(ControlMouseState)
Section titled “OnLeftMouseClicked(ControlMouseState)”Called when the left mouse button is clicked. Raises the MouseButtonClicked event and calls the DetermineState() method.
protected override void OnLeftMouseClicked(ControlBase.ControlMouseState state)Parameters
Section titled “Parameters”state ControlBase.ControlMouseState
The current mouse data
GetItemAndIndexUnderMouse(ControlMouseState)
Section titled “GetItemAndIndexUnderMouse(ControlMouseState)”Returns the item under the mouse, and its array position.
public (object? item, int itemIndex) GetItemAndIndexUnderMouse(ControlBase.ControlMouseState state)Parameters
Section titled “Parameters”state ControlBase.ControlMouseState
The mouse state.
Returns
Section titled “Returns”(object item, int itemIndex)
A tuple containing the item and the item’s array position.
Exceptions
Section titled “Exceptions”Exception
Thrown when the theme for the listbox isn’t based on ListBoxTheme.
SetupScrollBar()
Section titled “SetupScrollBar()”Sets up the scroll bar for the listbox.
protected virtual void SetupScrollBar()ShowHideScrollBar()
Section titled “ShowHideScrollBar()”Shows the scroll bar when there are too many items to display; otherwise, hides it.
protected void ShowHideScrollBar()RefreshThemeStateColors(Colors)
Section titled “RefreshThemeStateColors(Colors)”Updates the ThemeState by calling RefreshTheme(Colors) with the provided colors. Override this method to adjust how colors are used by the ThemeState.
protected override void RefreshThemeStateColors(Colors colors)Parameters
Section titled “Parameters”colors Colors
The colors to apply to the theme state.
UpdateAndRedraw(TimeSpan)
Section titled “UpdateAndRedraw(TimeSpan)”Updates each control hosted by this control.
public override void UpdateAndRedraw(TimeSpan time)Parameters
Section titled “Parameters”time TimeSpan
The game frame time delta.
Events
Section titled “Events”SelectedItemChanged
Section titled “SelectedItemChanged”An event that triggers when the SelectedItem property changes.
public event EventHandler<ListBox.SelectedItemEventArgs>? SelectedItemChangedEvent Type
Section titled “Event Type”EventHandler<ListBox.SelectedItemEventArgs>
SelectedItemReselected
Section titled “SelectedItemReselected”An event that triggers when the SelectedItem property is reselected by the mouse.
public event EventHandler<ListBox.SelectedItemEventArgs>? SelectedItemReselectedEvent Type
Section titled “Event Type”EventHandler<ListBox.SelectedItemEventArgs>
SelectedItemExecuted
Section titled “SelectedItemExecuted”An event that triggers when an item is double clicked or the Enter key is pressed while the listbox has focus.
public event EventHandler<ListBox.SelectedItemEventArgs>? SelectedItemExecuted