ListBox - ahatornn/clforms GitHub Wiki
ClForms.Elements.ListBox
Represents a Windows control to display a list of items
public class ListBox: ListBox<object>, IElementStyle<ListBox>Inheritance Control -> BaseFocusableControl -> ListBoxBase<T> -> ListBox
Derived IElementStyle<ListBox>
ListBox is derived from ListBox<T> where T defines the type of item in the list. For a ListBox, this type is
object. You can use ListBox<T> with the desired type T to get the items immediately in the needed type
The following code example demonstrates how to create a ListBox control that displays multiple items in columns. The code for the example adds 50 items to the ListBox using the Add method of the ListBox.ObjectCollection class.
var targetListBox = new ListBox<int>();
// Shutdown the painting of the ListBox as items are added.
targetListBox.BeginUpdate();
// Loop through and add 50 items to the ListBox.
for (int x = 1; x <= 50; x++)
{
targetListBox.Items.Add(x);
}
// Allow the ListBox to repaint and display the new items.
listBox1.EndUpdate();
targetListBox.FormatString = "item: {0}";
AddContent(targetListBox);You can find more examples of using the Label in this project
The Add method of the ListBox.ItemCollection class enables you to add items to the ListBox. The Add method can accept any object when adding a member to the ListBox. Use generic ListBox<> for accept specified object as ListBox items. When an object is being added to the ListBox, the control uses the text defined in the ToString method of the object unless a member name within the object is specified in the FormatString property.
| Syntax | Description |
|---|---|
| ListBox() | Initialize a new instance ListBox |
| Name | Type | Description |
|---|---|---|
| AutoSize | bool | Gets or sets a value indicating whether the control is resized in accordance with its contents |
| Background | Color | Gets or sets a brush that describes the background of a control |
| BackgroundIsTransparent | bool | Gets a value indicating whether the Background has Color.NotSet
|
| Bounds | Rect | Gets the size and location of the control including its nonclient elements, in points, relative to the parent control |
| DesiredSize | Size | Gets the size that this element computed during the measure pass of the layout process |
| DisabledBackground | Color | Gets or sets a value to display of background when the control is disabled |
| DisabledForeground | Color | Gets or sets a value to display of text color when the control is disabled |
| DrawingContext | IDrawingContext | Gets a value of the drawing context |
| FocusBackground | Color | Focused component background color |
| FocusForeground | Color | Focused component text color |
| Foreground | Color | Gets or sets a brush that describes the text of a control |
| ForegroundIsTransparent | bool | Gets a value indicating whether the Foreground has Color.NotSet
|
| FormatString | string | Gets or sets the format-specifier characters that indicate how a value is to be displayed |
| Height | int? | Gets or sets the height of the control |
| Id | long | Gets a value of the control's identifier |
| IsDisabled | bool | Gets or sets a value indicating whether the control cannot respond to user interaction |
| IsFocus | bool | Gets or sets focus value of component |
| IsInUpdateState | bool | Indicates whether the component is in collection item update mode |
| IsMeasureValid | bool | Gets a value indicating whether component sizing was performed |
| IsVisualValid | bool | Gets a value indicating whether the component is being re-rendered |
| Items | ItemCollection<T> | Gets all elements in ListBox |
| Location | Point | Gets or sets the coordinates of the upper-left corner of the control relative to the upper-left corner of its container |
| Margin | Thickness | Gets or sets the outer margin of an element |
| Padding | Thickness | Gets or sets a Thickness value that describes the amount of space between a control and its child element |
| Parent | ContentControl | Gets or sets the parent container of the control |
| SelectedBackground | Color | Gets or sets a value to display of background when the item is selected |
| SelectedForeground | Color | Gets or sets a value to display of foreground when the item is selected |
| SelectedIndex | int | Gets or sets the zero-based index of the currently selected item in a ListBox |
| SelectedItemBounds | Rect | Gets the Rect of selected item area |
| SelectionMode | SelectionMode | Gets or sets the method in which items are selected in the ListBox |
| TabIndex | int | Gets or sets the sequence for moving the TAB key between the controls inside the container |
| TabStop | bool | Gets or sets a value indicating whether the user can focus on the given control using the TAB key |
| Tag | object | Gets or sets the object that contains data about the control |
| TextAlignment | TextAlignment | Gets or sets the horizontal alignment of the contents of the text |
| Width | int? | Gets or sets the width of the control |
| Syntax | Description |
|---|---|
| Arrange(Rect) | Positions child elements and determines a size for a Control. Parent elements call this method from their Arrange(Rect) implementation to form a recursive layout update |
| BeginUpdate() | Maintains performance while items are added to the ListBox one at a time by preventing the control from drawing until the EndUpdate() method is called |
| CanFocus() | Indicates whether component focus can be set |
| ClearSelected() | Unselects all items in the ListBox |
| ClearSelected(T item) | Unselects specified item in the ListBox |
| EndUpdate() | Resumes painting the ListBox control after painting is suspended by the BeginUpdate() method |
| InputAction(ConsoleKeyInfo) | Handles a keystroke |
| InvalidateMeasure() | Invalidates the measurement state (layout) for the element |
| InvalidateMeasureIfAutoSize() | Invalidates the measurement state (layout) for the element if AutoSize property is true otherwise invalidates the rendering of the element |
| InvalidateVisual() | Invalidates the rendering of the element, and forces a complete new layout pass. OnRender(IDrawingContext) is called after the layout cycle is completed |
| Measure(Size) | Updates DesiredSize of a Control. Parent elements call this method from their own Measure(Size) implementations to form a recursive layout update |
| OnRender(IDrawingContext) | Filling a pseudographics drawing context |
| ParentWindow() | Gets the form the control is in |
| SetFocus() | Sets input focus to current item |
| SetStyle(Action) | Defines actions with an element style |
| Event | Description |
|---|---|
| OnAutoSizeChanged | Occurs when the value of the AutoSize property changes |
| OnBackgroundChanged | Occurs when the value of the Background property changes |
| OnClick | Occurs when the ButtonBase control is clicked |
| OnDisabledBackgroundChanged | Occurs when the value of the DisabledBackground property changes |
| OnDisabledChanged | Occurs when the value of the IsDisabled property changes |
| OnDisabledForegroundChanged | Occurs when the value of the DisabledForeground property changes |
| OnEnter | Input focus event |
| OnFocusBackgroundChanged | Occurs when the value of the FocusBackground property changes |
| OnFocusChanged | Occurs when the value of the IsFocus property changes |
| OnFocusForegroundChanged | Occurs when the value of the FocusForeground property changes |
| OnForegroundChanged | Occurs when the value of the Foreground property changes |
| OnFormatStringChanged | Occurs when the value of the FormatString property changes |
| OnHeightChanged | Occurs when the value of the Height property changes |
| OnLeave | Input focus loss event |
| OnMarginChanged | Occurs when the value of the Margin property changes |
| OnPaddingChanged | Occurs when the value of the Padding property changes |
| OnParentChanged | Occurs when the value of the Parent property changes |
| OnSelectedBackgroundChanged | Occurs when the value of the SelectedBackground property changes |
| OnSelectedForegroundChanged | Occurs when the value of the SelectedForeground property changes |
| OnSelectedIndexChanged | Occurs when the value of the SelectedIndex property changes |
| OnSelectedItemClick | Occurs when the selected item is clicked |
| OnSelectionModeChanged | Occurs when the value of the SelectionMode property changes |
| OnTabIndexChanged | Occurs when a property value of TabIndex changes |
| OnTabStopChanged | Occurs when a property value of TabStop changes |
| OnTagChanged | Occurs when the value of the Tag property changes |
| OnTextAlignmentChanged | Occurs when the value of the TextAlignment property changes |
| OnWidthChanged | Occurs when the value of the Width property changes |