CheckedImageListBox
A list box whose items carry a title, a line of description, an image and a check box – for task lists, feature pickers, notification lists and option lists that need more than one line of plain text.
public partial class CheckedImageListBox : ListBox
Inherits from / implements: ListBox
Remarks
What it is for
It is a ListBox in everything but the drawing – Items, the selection modes,
SelectedIndex, scrolling and the keyboard work as usual – so it can replace one directly. Every row
is measured and drawn by the control, with gradients, borders, hover highlighting and per-item colours
and fonts.
Items
Add CheckedImageListBoxItem objects to Items: each has a
CheckedImageListBoxItem.Title, CheckedImageListBoxItem.ContentText, an
CheckedImageListBoxItem.Image, a check state and its own tool tip. A plain string is shown as
content text with no title and no check box. Any other object is not drawn.
Check boxes
An item shows a check box when its CheckedImageListBoxItem.IsChecked is
true or false, and none when it is null (the default).
With CheckOnClick on, every click on an item toggles it; off, the first click selects an item
and a further click on it toggles it. Space toggles the selected item. Each toggle by the user raises
ItemCheckStateChanged.
Full view and collapsed view
With EnableItemFullView on (the default) every row shows its title and content text.
Off, each row is one line – check box, image, title – and only the selected rows open to show their
content text, which keeps a long list compact. The collapsed view needs every item to have a title.
Sizes
Spacings, margins, the check box size and the frame are in logical pixels (96 DPI) and scale with the display; images are drawn at their own pixel size. Windows limits a list box row to 255 device pixels, so a taller item is cut short.
Many appearance properties re-measure every item when set. When configuring a long list in code, set the appearance before adding the items.
Examples
using Binarymission.WinForms.Controls.ListControls;
var releaseTasks = new CheckedImageListBox
{
Location = new Point(12, 12),
Size = new Size(380, 340),
CheckOnClick = true,
ShouldDrawFrame = true,
ShouldShowDefaultTooltipOnItemHover = true,
ItemSelectedStartColor = Color.LightSteelBlue,
ItemUnselectedStartColor = Color.WhiteSmoke,
};
releaseTasks.Items.Add(new CheckedImageListBoxItem
{
Title = "Renew the TLS certificate",
ContentText = "The certificate on the web server expires in 9 days.",
Image = Image.FromFile(@"icons\certificate-32.png"),
IsChecked = false,
TooltipTitle = "Owner",
TooltipContent = "Infrastructure on-call",
});
releaseTasks.Items.Add(new CheckedImageListBoxItem
{
Title = "Publish release notes",
ContentText = "Version 4.2 - fixes for invoicing and the export to PDF.",
Image = Image.FromFile(@"icons\notes-32.png"),
IsChecked = true,
});
releaseTasks.ItemCheckStateChanged += (sender, e) =>
statusLabel.Text = e.CheckedImageListBoxItem.Title + (e.NewCheckState == true ? " - done" : " - reopened");
Controls.Add(releaseTasks);See also
Members at a glance
| Constructors | |
|---|---|
CheckedImageListBox | Initialises an empty list in single selection, full view, with item borders, warm gradient colours and check boxes allowed. |
| Properties | |
AnnotationImageOnMouseHover | Gets or sets the image shown at the right end of the item under the pointer. |
CheckBoxSize | Gets or sets the space reserved for an item's check box, and the size of a classic check box. |
CheckOnClick | Gets or sets whether a single click on an item toggles its check box. |
CheckedStateImage | Gets or sets the image shown for a checked item when check states are drawn as images. |
ContentStringFormat | Gets or sets how an item's content text is aligned, wrapped and trimmed. |
CreateParams | Gets the window's creation parameters; while ShouldDrawFrame is on, without
the border styles ListBox.BorderStyle asks for, since the frame replaces them. |
DrawMode | Gets the drawing mode, which is always OwnerDrawVariable: the control
measures and draws every row itself. |
EnableItemFullView | Gets or sets whether every row shows its content text, or only the selected rows (the collapsed view). |
FrameBorderColor | Gets or sets the colour of the frame's border (see ShouldDrawFrame). |
FrameBorderThickness | Gets or sets the thickness of the frame's border, in logical (96 DPI) pixels, 0 to 8. |
FrameCornerRadius | Gets or sets the radius of the frame's corners, in logical (96 DPI) pixels, 0 to 32. |
FrameFocusedBorderColor | Gets or sets the colour of the frame's border while the control has the focus.
Color.Empty keeps FrameBorderColor. |
FramePadding | Gets or sets the space between the frame's border and the items, in logical (96 DPI) pixels, 0 to 16. It is never less than the corners need to keep the items inside them. |
FrameShadowColor | Gets or sets the colour of the frame's drop shadow. Its strength is
FrameShadowOpacity, so the colour's own alpha is not used. |
FrameShadowDepth | Gets or sets how far the frame's shadow spreads, in logical (96 DPI) pixels, 0 to 24. A third of it is also the distance the shadow drops below the frame. |
FrameShadowOpacity | Gets or sets the strength of the frame's shadow at its darkest, as a percentage, 0 to 100. |
IsAnnotationEnabled | Gets or sets whether AnnotationImageOnMouseHover is shown at the right end of the item under
the pointer. |
IsChildOfPopupWindow | Gets or sets whether the list is shown inside a popup or drop-down window. |
IsImageDrawnWhenUsingDefaultItemTooltip | Gets or sets whether the control's own tool tip shows an information icon beside its title. |
IsItemCheckUncheckAllowed | Gets or sets whether items show check boxes and can be checked. |
IsItemSidebarBorderDrawingEnabled | Gets or sets whether the sidebar strip (see IsItemSidebarDrawingEnabled) has an outline. |
IsItemSidebarDrawingEnabled | Gets or sets whether a coloured strip is drawn down the left of the selected item and of the item under the pointer. |
IsReadOnly | Gets or sets whether the list is for looking only: it can be scrolled, but not selected or checked. |
ItemAlternateEndColor | Gets or sets the second colour of the background gradient of every second unselected item. |
ItemAlternateGradientFactor | Gets or sets the direction of every unselected item's gradient while alternating colours are on. |
ItemAlternateStartColor | Gets or sets the first colour of the background gradient of every second unselected item. |
ItemContentFont | Gets or sets the font of every item's content text. |
ItemContentTextColor | Gets or sets the content text colour of a selected item. |
ItemDisabledContentTextColor | Gets or sets the colour of the items' content text while the control is disabled. |
ItemDisabledEndColor | Gets or sets a second background colour for a disabled control, which the drawing does not use. |
ItemDisabledStartColor | Gets or sets the first colour of every item's background gradient, and the border colour, while the control is disabled. |
ItemDisabledTitleTextColor | Gets or sets the colour of the items' titles while the control is disabled. |
ItemMouseHoverBorderColor | Gets or sets the border colour of the unselected item under the pointer. |
ItemMouseHoverBorderThickness | Gets or sets the width of the border of the item under the pointer. |
ItemMouseHoverContentTextForeColor | Gets or sets the content text colour of the unselected item under the pointer. |
ItemMouseHoverEndColor | Gets or sets the second colour of the background gradient of the unselected item under the pointer. |
ItemMouseHoverGradientFactor | Gets or sets the direction of the background gradient of the unselected item under the pointer. |
ItemMouseHoverStartColor | Gets or sets the first colour of the background gradient of the unselected item under the pointer. |
ItemMouseHoverTitleForeColor | Gets or sets the title colour of the unselected item under the pointer. |
ItemReadOnlyBorderColor | Gets or sets every item's border colour while IsReadOnly is on or SelectionMode
is None. |
ItemReadOnlyContentTextColor | Gets or sets the colour of every item's content text while IsReadOnly is on. |
ItemReadOnlyEndColor | Gets or sets the second colour of every item's background gradient while IsReadOnly is on
or SelectionMode is None. |
ItemReadOnlyStartColor | Gets or sets the first colour of every item's background gradient while IsReadOnly is on
or SelectionMode is None. |
ItemReadOnlyTitleTextColor | Gets or sets the colour of every title while IsReadOnly is on. |
ItemSelectedBorderColor | Gets or sets the border colour of a selected item. |
ItemSelectedBorderThickness | Gets or sets the width of a selected item's border. |
ItemSelectedEndColor | Gets or sets the second colour of a selected item's background gradient. |
ItemSelectedGradientFactor | Gets or sets the direction of a selected item's background gradient. |
ItemSelectedStartColor | Gets or sets the first colour of a selected item's background gradient. |
ItemSpacing | Gets or sets the gap left below each item. |
ItemTitleFont | Gets or sets the font of every item's title. |
ItemTitleTextColor | Gets or sets the title colour of a selected item. |
ItemTooltipContentFont | Gets or sets the font of the tool tip text in the control's own tool tip. |
ItemTooltipTitleFont | Gets or sets the font of the tool tip title in the control's own tool tip. |
ItemUnselectedBorderColor | Gets or sets the border colour of an unselected item. |
ItemUnselectedBorderThickness | Gets or sets the width of the border of an unselected item. |
ItemUnselectedContentTextColor | Gets or sets the content text colour of an unselected item. |
ItemUnselectedEndColor | Gets or sets the second colour of an unselected item's background gradient. |
ItemUnselectedGradientFactor | Gets or sets the direction of an unselected item's background gradient. |
ItemUnselectedStartColor | Gets or sets the first colour of an unselected item's background gradient. |
ItemUnselectedTitleTextColor | Gets or sets the title colour of an unselected item. |
MinimumItemTopAndBottomMargin | Gets or sets the space kept above and below an item's content inside its row. |
PaddingBetweenItemComponents | Gets or sets the gap between the parts of an item: the edge, the check box, the image and the text. |
SelectionMode | Gets or sets how many items can be selected at once, and how. |
ShouldAnimateItemImage | Gets or sets whether the selected item's image is lifted by one pixel, so it appears to rise when the item is selected. |
ShouldDrawCheckBoxInVisualStyle | Gets or sets whether check boxes are drawn in the current Windows theme rather than the classic style. |
ShouldDrawFrame | Gets or sets a value indicating whether the control draws its own frame: a border with rounded corners, an inner padding and, optionally, a drop shadow, all inside its bounds. |
ShouldDrawFrameShadow | Gets or sets a value indicating whether the frame casts a soft drop shadow. |
ShouldDrawItemBorder | Gets or sets whether a border is drawn around each item. |
ShouldDrawTopItemSpacingForFirstItem | Gets or sets whether a gap of ItemSpacing is left above the first item, as there is below every
item. |
ShouldEnableAlternatingColors | Gets or sets whether every second unselected item (the second, fourth and so on) is drawn in the alternate colours, for a striped list. |
ShouldExpandItemFullViewUponClick | Gets or sets whether, in the collapsed view, the rows are re-measured as soon as the mouse button goes down, so a clicked row opens on the press rather than after the release. |
ShouldRefreshBasedOnMessage | Gets or sets how the control applies new row heights: by sending them to the list box window, or by recreating the window. |
ShouldShowDefaultTooltipOnItemHover | Gets or sets whether the control shows its own tool tip for an item with
CheckedImageListBoxItem.TooltipContent: the item's tool tip title over its content. |
ShouldUseImageForCheckState | Gets or sets whether every item's check state is shown with CheckedStateImage and
UncheckedStateImage instead of a check box. |
SidebarBorderThickness | Gets or sets the width of the sidebar strip's outline. |
SidebarGradientMode | Gets or sets the direction of the sidebar strip's gradient. |
SidebarItemHoveredStateBorderColor | Gets or sets the colour of the sidebar strip's outline on the item under the pointer. |
SidebarItemHoveredStateEndColor | Gets or sets the second colour of the sidebar strip's gradient on the item under the pointer. |
SidebarItemHoveredStateStartColor | Gets or sets the first colour of the sidebar strip's gradient on the item under the pointer. |
SidebarItemSelectedStateBorderColor | Gets or sets the colour of the sidebar strip's outline on the selected item. |
SidebarItemSelectedStateEndColor | Gets or sets the second colour of the sidebar strip's gradient on the selected item. |
SidebarItemSelectedStateStartColor | Gets or sets the first colour of the sidebar strip's gradient on the selected item. |
SidebarWidth | Gets or sets the width of the sidebar strip. |
TitleStringFormat | Gets or sets how an item's title is aligned, wrapped and trimmed. |
UncheckedStateImage | Gets or sets the image shown for an unchecked item when check states are drawn as images. |
| Methods | |
DefWndProc | Passes a message to the list box's default handling, except a click on the check box of an item in a
multiple selection with CheckOnClick on, which only toggles the check and keeps the
selection. |
OnDrawItem | Raises ListBox.DrawItem and draws the row: background, border, sidebar, check box, image,
title, content text and annotation image. |
OnHandleCreated | Raises Control.HandleCreated, then puts back the height the list was given. |
OnKeyDown | Raises Control.KeyDown. Up on the first item and Down on the last are marked handled, so
holding them does not repeat a selection change that changes nothing. |
OnKeyUp | Raises Control.KeyUp; Space then toggles the selected item's check box and raises
ItemCheckStateChanged. |
OnMeasureItem | Raises ListBox.MeasureItem and sets the row's height from its content, image, check box,
margins and spacing – at most 255 device pixels, the Windows limit. |
OnMouseDown | Raises Control.MouseDown and notes the item pressed, which the release then checks or
selects. |
OnMouseLeave | Raises Control.MouseLeave, hides the tool tip and raises ItemHoverChanged with
no item. |
OnMouseMove | Raises Control.MouseMove and tracks the hovered item: its highlight, its tool tip and
ItemHoverChanged. |
OnMouseUp | Raises Control.MouseUp, then completes a click: ItemImageClicked or
AnnotationImageClicked when the image was hit, the check toggle (see CheckOnClick)
and the selection. |
OnMouseWheel | Raises Control.MouseWheel; the list scrolls in the usual way. |
OnPaint | Raises Control.Paint, fills the background with Control.BackColor and draws
every visible row. |
OnResize | Raises Control.Resize and measures every item again for the new width, since text wraps
differently. |
OnSelectedIndexChanged | Raises ListBox.SelectedIndexChanged and re-measures the rows whose view changes with the
selection. |
PerformDeterministicRefresh | Measures every item again and applies the new heights, without repainting. |
PerformRefreshMeasurePaint | Measures every item again and repaints the list, keeping the same item at the top. |
ProcessCmdKey | Handles the list's shortcuts while it has the focus: Ctrl+A selects every item (in the multiple selection modes) and Ctrl+C copies the selected items – or every item when none is selected – to the clipboard as text. |
ScrollIntoView | Scrolls the list so that an item is at the top, and optionally selects it. |
SelectAll | Selects every item, as Ctrl+A does, and scrolls back to the first. |
SetBoundsCore | Performs the work of setting the bounds of this control, remembering the height asked for. |
SetCheckState | Checks, unchecks or removes the check box of one item, or of every item. |
UnselectAll | Clears the selection and selects the first item. |
WndProc | Processes the list's window messages, reserving and painting the frame (see ShouldDrawFrame)
and raising VerticalScroll after the wheel or a key has scrolled the list. |
| Events | |
AnnotationImageClicked | Occurs when the user clicks the annotation image shown at the right of the hovered item. |
ItemCheckStateChanged | Occurs when an item's check box is toggled: by a click, by the Space key, or by
SetCheckState for one item. |
ItemHoverChanged | Occurs when the pointer moves onto an item that has a tool tip, and when it leaves the control. |
ItemImageClicked | Occurs when the user clicks an item's image. |
ItemTooltipAboutToDraw | Occurs when an item's tool tip is about to be drawn, so that you can draw it yourself. |
ItemTooltipAboutToPopup | Occurs when an item's tool tip is about to appear, so that you can size it or cancel it. |
VerticalScroll | Occurs when the list scrolls through the mouse wheel, the keyboard or ScrollIntoView. |
Constructors
CheckedImageListBox
Initialises an empty list in single selection, full view, with item borders, warm gradient colours and check boxes allowed.
Properties
AnnotationImageOnMouseHover
Gets or sets the image shown at the right end of the item under the pointer.
- Value
- The default is
null: none.
Remarks
Shown only while IsAnnotationEnabled is on, 8 pixels in from the right edge and at most
32 by 32 pixels; a larger image is squeezed to fit.
Example
inbox.AnnotationImageOnMouseHover = Image.FromFile(@"icons\archive-16.png");
inbox.IsAnnotationEnabled = true;
inbox.AnnotationImageClicked += (sender, e) =>
{
int index = inbox.IndexFromPoint(inbox.PointToClient(Cursor.Position));
if (index >= 0)
{
inbox.Items.RemoveAt(index);
}
};CheckBoxSize
Gets or sets the space reserved for an item's check box, and the size of a classic check box.
- Value
- In logical pixels. The default is 16 by 16.
Remarks
A classic check box (ShouldDrawCheckBoxInVisualStyle off) is drawn at this size; a themed
one keeps the theme's size inside this space. Check-state images are drawn at their own size instead.
Setting ShouldDrawCheckBoxInVisualStyle to true resets it, so set it
afterwards. The rows are not
re-measured: call PerformRefreshMeasurePaint after changing it.
CheckOnClick
Gets or sets whether a single click on an item toggles its check box.
- Value
- The default is
false: the first click on an item selects it, and a further click on the same item toggles it.
Remarks
With it on, a click anywhere on the row toggles the check, except a Ctrl or Shift click in
MultiExtended, which only changes the selection. A click on the
check box of an item inside a multiple selection toggles it without losing the selection.
Either way only items with a check box toggle, and nothing toggles while
IsItemCheckUncheckAllowed is off or IsReadOnly is on.
CheckedStateImage
Gets or sets the image shown for a checked item when check states are drawn as images.
- Value
- The default is
null.
See also
ContentStringFormat
Gets or sets how an item's content text is aligned, wrapped and trimmed.
- Value
- By default top-left aligned, trimmed with an ellipsis.
Remarks
Setting it re-measures every item.
CreateParams
Gets the window's creation parameters; while ShouldDrawFrame is on, without
the border styles ListBox.BorderStyle asks for, since the frame replaces them.
DrawMode
Gets the drawing mode, which is always OwnerDrawVariable: the control
measures and draws every row itself.
- Value
OwnerDrawVariable. Assigning another value has no effect.
EnableItemFullView
Gets or sets whether every row shows its content text, or only the selected rows (the collapsed view).
- Value
true(the default) for the full view.
Remarks
In the collapsed view each row is one line – check box, image and title – and the selected rows open to show their content text below. It suits long lists and drop-downs.
The collapsed view needs every item to be a CheckedImageListBoxItem with a
CheckedImageListBoxItem.Title: while any item is not, this property reads
true whatever was set.
Changing it while items are selected clears the selection and selects the first item.
See also
FrameBorderColor
Gets or sets the colour of the frame's border (see ShouldDrawFrame).
- Value
- The default is a light blue-grey (
196, 204, 216). - Default
196, 204, 216
FrameBorderThickness
Gets or sets the thickness of the frame's border, in logical (96 DPI) pixels, 0 to 8.
- Value
- The default is 1.
- Default
1
FrameCornerRadius
Gets or sets the radius of the frame's corners, in logical (96 DPI) pixels, 0 to 32.
- Value
- The default is 6.
- Default
6
FrameFocusedBorderColor
Gets or sets the colour of the frame's border while the control has the focus.
Color.Empty keeps FrameBorderColor.
- Value
- The default is
Color.Empty. - Default
FramePadding
Gets or sets the space between the frame's border and the items, in logical (96 DPI) pixels, 0 to 16. It is never less than the corners need to keep the items inside them.
- Value
- The default is 3.
- Default
3
FrameShadowColor
Gets or sets the colour of the frame's drop shadow. Its strength is
FrameShadowOpacity, so the colour's own alpha is not used.
- Value
- The default is
Color.Black. - Default
Black
FrameShadowDepth
Gets or sets how far the frame's shadow spreads, in logical (96 DPI) pixels, 0 to 24. A third of it is also the distance the shadow drops below the frame.
- Value
- The default is 6.
- Default
6
FrameShadowOpacity
Gets or sets the strength of the frame's shadow at its darkest, as a percentage, 0 to 100.
- Value
- The default is 16.
- Default
16
IsAnnotationEnabled
Gets or sets whether AnnotationImageOnMouseHover is shown at the right end of the item under
the pointer.
- Value
- The default is
false.
Remarks
Clicking the image raises AnnotationImageClicked – a natural place for an item action
such as "open" or "remove".
IsChildOfPopupWindow
Gets or sets whether the list is shown inside a popup or drop-down window.
- Value
- The default is
false.
Remarks
A popup's focus handling can swallow the press that starts a click. With this on, a click is taken on the item under the pointer when the button comes up; off, a click counts only when the button comes up over the item it went down on.
IsImageDrawnWhenUsingDefaultItemTooltip
Gets or sets whether the control's own tool tip shows an information icon beside its title.
- Value
- The default is
false.
See also
IsItemCheckUncheckAllowed
Gets or sets whether items show check boxes and can be checked.
- Value
- The default is
true.
Remarks
Turning it off hides every check box by setting each item's CheckedImageListBoxItem.IsChecked
to null; the states are remembered and given back, to the items still in the list, when it is
turned on again. While it is off, clicks, Space and SetCheckState change nothing.
IsItemSidebarBorderDrawingEnabled
Gets or sets whether the sidebar strip (see IsItemSidebarDrawingEnabled) has an outline.
- Value
- The default is
false.
IsItemSidebarDrawingEnabled
Gets or sets whether a coloured strip is drawn down the left of the selected item and of the item under the pointer.
- Value
- The default is
false.
Remarks
The strip is SidebarWidth wide and moves the item's content right by as much. Its colours
are the SidebarItemSelectedState... ones on the selected item and the SidebarItemHoveredState...
ones on the hovered item.
IsReadOnly
Gets or sets whether the list is for looking only: it can be scrolled, but not selected or checked.
- Value
- The default is
false.
Remarks
Turning it on clears the selection, switches SelectionMode to
None and draws the items in the read-only colours
(ItemReadOnlyStartColor and its neighbours). Turning it off restores the selection mode the
list had, or the one set meanwhile.
Items' check states are kept, and can still be changed from code.
ItemAlternateEndColor
Gets or sets the second colour of the background gradient of every second unselected item.
- Value
- The default is
Color.White.
Remarks
Used only while ShouldEnableAlternatingColors is on.
ItemAlternateGradientFactor
Gets or sets the direction of every unselected item's gradient while alternating colours are on.
- Value
- In degrees clockwise from left-to-right: 0 runs the start colour to the end colour from left to right, 90 from top to bottom, 270 from bottom to top. The default is 90.
ItemAlternateStartColor
Gets or sets the first colour of the background gradient of every second unselected item.
- Value
- The default is
Color.Wheat.
Remarks
Used only while ShouldEnableAlternatingColors is on.
ItemContentFont
Gets or sets the font of every item's content text.
- Value
- By default the control's
Control.Fontwhen it was created. An item's ownCheckedImageListBoxItem.ContentTextFontoverrides it.
ItemContentTextColor
Gets or sets the content text colour of a selected item.
- Value
- The default is
Color.Black.
Remarks
An item's own CheckedImageListBoxItem.ContentTextColor overrides it.
ItemDisabledContentTextColor
Gets or sets the colour of the items' content text while the control is disabled.
- Value
- The default is
SystemColors.GrayText.
Remarks
The titles use ItemDisabledTitleTextColor.
ItemDisabledEndColor
Gets or sets a second background colour for a disabled control, which the drawing does not use.
- Value
- The default is
SystemColors.Window.
Remarks
A disabled control's item backgrounds run from ItemDisabledStartColor to white.
ItemDisabledStartColor
Gets or sets the first colour of every item's background gradient, and the border colour, while the control is disabled.
- Value
- The default is
SystemColors.GrayText.
Remarks
The gradient runs from this colour to white.
ItemDisabledTitleTextColor
Gets or sets the colour of the items' titles while the control is disabled.
- Value
- The default is
SystemColors.GrayText.
Remarks
The content text uses ItemDisabledContentTextColor.
ItemMouseHoverBorderColor
Gets or sets the border colour of the unselected item under the pointer.
- Value
- The default is
Color.DarkBlue.
ItemMouseHoverBorderThickness
Gets or sets the width of the border of the item under the pointer.
- Value
- In pixels, not scaled with the display. The default is 1.
ItemMouseHoverContentTextForeColor
Gets or sets the content text colour of the unselected item under the pointer.
- Value
- The default is
Color.Blue.
ItemMouseHoverEndColor
Gets or sets the second colour of the background gradient of the unselected item under the pointer.
- Value
- The default is
Color.White.
ItemMouseHoverGradientFactor
Gets or sets the direction of the background gradient of the unselected item under the pointer.
- Value
- In degrees clockwise from left-to-right: 0 runs the start colour to the end colour from left to right, 90 from top to bottom, 270 from bottom to top. The default is 90.
ItemMouseHoverStartColor
Gets or sets the first colour of the background gradient of the unselected item under the pointer.
- Value
- The default is
Color.SkyBlue.
ItemMouseHoverTitleForeColor
Gets or sets the title colour of the unselected item under the pointer.
- Value
- The default is
Color.BlueViolet.
ItemReadOnlyBorderColor
Gets or sets every item's border colour while IsReadOnly is on or SelectionMode
is None.
- Value
- The default is
Color.Black.
ItemReadOnlyContentTextColor
Gets or sets the colour of every item's content text while IsReadOnly is on.
- Value
- The default is
Color.Black.
Remarks
Overrides the item's own CheckedImageListBoxItem.ContentTextColor.
ItemReadOnlyEndColor
Gets or sets the second colour of every item's background gradient while IsReadOnly is on
or SelectionMode is None.
- Value
- The default is
Color.White.
ItemReadOnlyStartColor
Gets or sets the first colour of every item's background gradient while IsReadOnly is on
or SelectionMode is None.
- Value
- The default is
Color.GhostWhite.
ItemReadOnlyTitleTextColor
Gets or sets the colour of every title while IsReadOnly is on.
- Value
- The default is
Color.Black.
Remarks
Overrides the item's own CheckedImageListBoxItem.TitleTextColor.
ItemSelectedBorderColor
Gets or sets the border colour of a selected item.
- Value
- The default is
Color.Red.
ItemSelectedBorderThickness
Gets or sets the width of a selected item's border.
- Value
- In logical pixels. The default is 1.
ItemSelectedEndColor
Gets or sets the second colour of a selected item's background gradient.
- Value
- The default is
Color.White.
ItemSelectedGradientFactor
Gets or sets the direction of a selected item's background gradient.
- Value
- In degrees clockwise from left-to-right: 0 runs the start colour to the end colour from left to right, 90 from top to bottom, 270 from bottom to top. The default is 90.
ItemSelectedStartColor
Gets or sets the first colour of a selected item's background gradient.
- Value
- The default is
Color.LightSalmon.
ItemSpacing
Gets or sets the gap left below each item.
- Value
- In logical pixels, from 0 to 24; any other value is stored as 6. The default is 6.
See also
ItemTitleFont
Gets or sets the font of every item's title.
- Value
- By default 10-point bold in the control's font family. An item's own
CheckedImageListBoxItem.TitleFontoverrides it.
ItemTitleTextColor
Gets or sets the title colour of a selected item.
- Value
- The default is
Color.Brown.
Remarks
An item's own CheckedImageListBoxItem.TitleTextColor overrides it.
ItemTooltipContentFont
Gets or sets the font of the tool tip text in the control's own tool tip.
- Value
- By default the control's
Control.Fontwhen it was created.
See also
ItemTooltipTitleFont
Gets or sets the font of the tool tip title in the control's own tool tip.
- Value
- By default 10-point bold in the control's font family.
See also
ItemUnselectedBorderColor
Gets or sets the border colour of an unselected item.
- Value
- The default is
Color.BurlyWood.
Remarks
An item's own CheckedImageListBoxItem.BorderColor overrides it.
ItemUnselectedBorderThickness
Gets or sets the width of the border of an unselected item.
- Value
- In pixels, not scaled with the display. The default is 1. An item's own
CheckedImageListBoxItem.BorderThicknessoverrides it.
ItemUnselectedContentTextColor
Gets or sets the content text colour of an unselected item.
- Value
- The default is
Color.Brown.
Remarks
An item's own CheckedImageListBoxItem.ContentTextColor overrides it.
ItemUnselectedEndColor
Gets or sets the second colour of an unselected item's background gradient.
- Value
- The default is
Color.White.
Remarks
An item's own CheckedImageListBoxItem.BackgroundEndColor overrides it.
ItemUnselectedGradientFactor
Gets or sets the direction of an unselected item's background gradient.
- Value
- In degrees clockwise from left-to-right: 0 runs the start colour to the end colour from left to right, 90 from top to bottom, 270 from bottom to top. The default is 270.
ItemUnselectedStartColor
Gets or sets the first colour of an unselected item's background gradient.
- Value
- The default is
Color.NavajoWhite.
Remarks
An item's own CheckedImageListBoxItem.BackgroundStartColor overrides it.
ItemUnselectedTitleTextColor
Gets or sets the title colour of an unselected item.
- Value
- The default is
Color.Black.
Remarks
An item's own CheckedImageListBoxItem.TitleTextColor overrides it.
MinimumItemTopAndBottomMargin
Gets or sets the space kept above and below an item's content inside its row.
- Value
- In logical pixels. The default is 10.
PaddingBetweenItemComponents
Gets or sets the gap between the parts of an item: the edge, the check box, the image and the text.
- Value
- In logical pixels. The default is 8.
SelectionMode
Gets or sets how many items can be selected at once, and how.
- Value
- The default is
One.
Remarks
While IsReadOnly is on, the list stays at None
and a mode you set is remembered and applied when it is turned off.
With None the items are drawn in the read-only colours,
and clicks do not check them. Setting the mode re-measures every item.
ShouldAnimateItemImage
Gets or sets whether the selected item's image is lifted by one pixel, so it appears to rise when the item is selected.
- Value
- The default is
false.
ShouldDrawCheckBoxInVisualStyle
Gets or sets whether check boxes are drawn in the current Windows theme rather than the classic style.
- Value
- The default is
true.
Remarks
A themed check box is drawn at the theme's own size, in the space CheckBoxSize reserves.
Setting this property to true resets CheckBoxSize to 16 by 16.
ShouldDrawFrame
Gets or sets a value indicating whether the control draws its own frame: a border with rounded corners, an inner padding and, optionally, a drop shadow, all inside its bounds.
- Value
- The default is
false. Turning it on or off recreates the window. - Default
false
Remarks
The frame replaces ListBox.BorderStyle, which is ignored while this is on.
It is painted in the control's own non-client area, so the items, the scroll bar and the
hit testing all sit inside it. Outside the border – the shadow and the rounded corners –
the control paints the background colour of the nearest parent that has an opaque one.
ShouldDrawFrameShadow
Gets or sets a value indicating whether the frame casts a soft drop shadow.
- Value
- The default is
true. Drawn only whileShouldDrawFrameis on. - Default
true
ShouldDrawItemBorder
Gets or sets whether a border is drawn around each item.
- Value
- The default is
true.
Remarks
An item's own CheckedImageListBoxItem.ShouldDrawItemBorder of false removes
its border while it is unselected; true gives it a border when selected even while this is
off.
ShouldDrawTopItemSpacingForFirstItem
Gets or sets whether a gap of ItemSpacing is left above the first item, as there is below every
item.
- Value
- The default is
false.
ShouldEnableAlternatingColors
Gets or sets whether every second unselected item (the second, fourth and so on) is drawn in the alternate colours, for a striped list.
- Value
- The default is
false.
Remarks
While it is on, every unselected item's gradient runs in the direction of
ItemAlternateGradientFactor.
ShouldExpandItemFullViewUponClick
Gets or sets whether, in the collapsed view, the rows are re-measured as soon as the mouse button goes down, so a clicked row opens on the press rather than after the release.
- Value
- The default is
false.
See also
ShouldRefreshBasedOnMessage
Gets or sets how the control applies new row heights: by sending them to the list box window, or by recreating the window.
- Value
true(the default, and recommended) to send each item's new height to the existing window;falseto recreate the window, which re-measures everything but is slower and can flicker.
ShouldShowDefaultTooltipOnItemHover
Gets or sets whether the control shows its own tool tip for an item with
CheckedImageListBoxItem.TooltipContent: the item's tool tip title over its content.
- Value
- The default is
false: no tool tip unless you handleItemTooltipAboutToPopupandItemTooltipAboutToDraw.
Remarks
The tip appears a tenth of a second after the pointer rests on the item and stays for four seconds,
drawn in the system tool tip colours with ItemTooltipTitleFont and
ItemTooltipContentFont.
ShouldUseImageForCheckState
Gets or sets whether every item's check state is shown with CheckedStateImage and
UncheckedStateImage instead of a check box.
- Value
- The default is
false. An item can choose images for itself with its ownCheckedImageListBoxItem.ShouldUseImageForCheckState.
Remarks
The images are drawn at their own size. An item's own CheckedImageListBoxItem.CheckedStateImage
and CheckedImageListBoxItem.UncheckedStateImage win over the control's.
Example
featureList.CheckedStateImage = Image.FromFile(@"icons\toggle-on-24.png");
featureList.UncheckedStateImage = Image.FromFile(@"icons\toggle-off-24.png");
featureList.ShouldUseImageForCheckState = true;SidebarBorderThickness
Gets or sets the width of the sidebar strip's outline.
- Value
- In pixels, not scaled with the display. The default is 1; 0 draws no outline.
SidebarGradientMode
Gets or sets the direction of the sidebar strip's gradient.
- Value
- The default is
Horizontal.
SidebarItemHoveredStateBorderColor
Gets or sets the colour of the sidebar strip's outline on the item under the pointer.
- Value
- The default is
Color.Black.
SidebarItemHoveredStateEndColor
Gets or sets the second colour of the sidebar strip's gradient on the item under the pointer.
- Value
- The default is
Color.LightBlue.
SidebarItemHoveredStateStartColor
Gets or sets the first colour of the sidebar strip's gradient on the item under the pointer.
- Value
- The default is
Color.Blue.
SidebarItemSelectedStateBorderColor
Gets or sets the colour of the sidebar strip's outline on the selected item.
- Value
- The default is
Color.Black.
SidebarItemSelectedStateEndColor
Gets or sets the second colour of the sidebar strip's gradient on the selected item.
- Value
- The default is
Color.BurlyWood.
SidebarItemSelectedStateStartColor
Gets or sets the first colour of the sidebar strip's gradient on the selected item.
- Value
- The default is
Color.Brown.
SidebarWidth
Gets or sets the width of the sidebar strip.
- Value
- In logical pixels. The default is 12; 0 draws no strip.
TitleStringFormat
Gets or sets how an item's title is aligned, wrapped and trimmed.
- Value
- By default top-left aligned, trimmed with an ellipsis.
Remarks
The collapsed view uses a copy that does not wrap. Setting it re-measures every item.
UncheckedStateImage
Gets or sets the image shown for an unchecked item when check states are drawn as images.
- Value
- The default is
null.
See also
Methods
DefWndProc
Passes a message to the list box's default handling, except a click on the check box of an item in a
multiple selection with CheckOnClick on, which only toggles the check and keeps the
selection.
Parameters
m- The message.
OnDrawItem
Raises ListBox.DrawItem and draws the row: background, border, sidebar, check box, image,
title, content text and annotation image.
Parameters
e- The draw data.
OnHandleCreated
Raises Control.HandleCreated, then puts back the height the list was given.
Parameters
e- The event data.
Remarks
With ListBox.IntegralHeight on, Windows fits a new window to the whole items it holds, and a
newly created window holds none yet. Many properties of this control recreate the window, so the height
asked for is restored each time.
OnKeyDown
Raises Control.KeyDown. Up on the first item and Down on the last are marked handled, so
holding them does not repeat a selection change that changes nothing.
Parameters
e- The key data.
OnKeyUp
Raises Control.KeyUp; Space then toggles the selected item's check box and raises
ItemCheckStateChanged.
Parameters
e- The key data.
OnMeasureItem
Raises ListBox.MeasureItem and sets the row's height from its content, image, check box,
margins and spacing – at most 255 device pixels, the Windows limit.
Parameters
e- The measure data.
OnMouseDown
Raises Control.MouseDown and notes the item pressed, which the release then checks or
selects.
Parameters
e- The mouse data.
OnMouseLeave
Raises Control.MouseLeave, hides the tool tip and raises ItemHoverChanged with
no item.
Parameters
e- The event data.
OnMouseMove
Raises Control.MouseMove and tracks the hovered item: its highlight, its tool tip and
ItemHoverChanged.
Parameters
e- The mouse data.
OnMouseUp
Raises Control.MouseUp, then completes a click: ItemImageClicked or
AnnotationImageClicked when the image was hit, the check toggle (see CheckOnClick)
and the selection.
Parameters
e- The mouse data.
Remarks
A click counts only when the button comes up over the item it went down on, unless
IsChildOfPopupWindow is on.
OnMouseWheel
Raises Control.MouseWheel; the list scrolls in the usual way.
Parameters
e- The wheel data.
OnPaint
Raises Control.Paint, fills the background with Control.BackColor and draws
every visible row.
Parameters
e- The paint data.
OnResize
Raises Control.Resize and measures every item again for the new width, since text wraps
differently.
Parameters
e- The event data.
OnSelectedIndexChanged
Raises ListBox.SelectedIndexChanged and re-measures the rows whose view changes with the
selection.
Parameters
e- The event data.
PerformDeterministicRefresh
Measures every item again and applies the new heights, without repainting.
Remarks
Use it after changing items' text, fonts or images in place, then call
Control.Invalidate; PerformRefreshMeasurePaint does both and keeps the top item
in view.
PerformRefreshMeasurePaint
Measures every item again and repaints the list, keeping the same item at the top.
Remarks
Call it after changing items in place – their text, fonts, images or colours – since the list does not watch its items.
Example
var item = (CheckedImageListBoxItem)taskList.Items[3];
item.ContentText = "Moved to Thursday - waiting for the supplier's quote.";
item.Image = Image.FromFile(@"icons\clock-32.png");
taskList.PerformRefreshMeasurePaint();ProcessCmdKey
Handles the list's shortcuts while it has the focus: Ctrl+A selects every item (in the multiple selection modes) and Ctrl+C copies the selected items – or every item when none is selected – to the clipboard as text.
Parameters
msg- The key message.
keyData- The key and modifiers.
Returns
true when the key was one of these shortcuts; otherwise the base answer.
Remarks
Each copied item is its ToString text: for a
CheckedImageListBoxItem, its title and content on two lines.
ScrollIntoView
Scrolls the list so that an item is at the top, and optionally selects it.
Parameters
index- The item's index, from 0 to
Items.Count - 1. autoSelecttrueto make it theListBox.SelectedIndexas well (ignored whenSelectionModeisNone).
Returns
true when index is a valid item; false, with
nothing done, otherwise.
Remarks
Raises VerticalScroll with ThumbPosition. The list cannot scroll past its last
page, so an item near the end stays below the top.
Example
int overdue = FindFirstOverdueTask();
if (!taskList.ScrollIntoView(overdue, true))
{
statusLabel.Text = "No overdue tasks";
}SelectAll
Selects every item, as Ctrl+A does, and scrolls back to the first.
Remarks
SetBoundsCore
Performs the work of setting the bounds of this control, remembering the height asked for.
Parameters
x- The new left edge.
y- The new top edge.
width- The new width.
height- The new height.
specified- Which of the bounds are being set.
SetCheckState
Checks, unchecks or removes the check box of one item, or of every item.
Parameters
index- The item's index, or -1 (the default) for every item. An index outside the list does nothing.
isCheckedtrue(the default) to check,falseto uncheck,nullto remove the check box.
Remarks
Does nothing while IsItemCheckUncheckAllowed is off. For a single item it raises
ItemCheckStateChanged; for every item it raises nothing, and plain string items are
skipped. An index that names a plain string item is ignored.
Example
taskList.SetCheckState(); // check everything
taskList.SetCheckState(-1, false); // uncheck everything
taskList.SetCheckState(2, null); // no check box on the third itemUnselectAll
Clears the selection and selects the first item.
Remarks
With no items, or while SelectionMode is
None (as it is while IsReadOnly is on), nothing is
selected.
WndProc
Processes the list's window messages, reserving and painting the frame (see ShouldDrawFrame)
and raising VerticalScroll after the wheel or a key has scrolled the list.
Parameters
m- The message.
Events
AnnotationImageClicked
Occurs when the user clicks the annotation image shown at the right of the hovered item.
Remarks
Needs IsAnnotationEnabled on and AnnotationImageOnMouseHover set. The event
carries no data: the item is the one under the pointer. Not raised while IsReadOnly is on or
when SelectionMode is None.
ItemCheckStateChanged
Occurs when an item's check box is toggled: by a click, by the Space key, or by
SetCheckState for one item.
Remarks
The arguments carry the item and its old and new CheckedImageListBoxItem.IsChecked
values. Raised after the item has changed and before it is repainted.
Not raised by SetCheckState for all items (index -1), by setting
CheckedImageListBoxItem.IsChecked directly, or by IsItemCheckUncheckAllowed.
Example
featureList.ItemCheckStateChanged += (sender, e) =>
{
var feature = (LicensedFeature)e.CheckedImageListBoxItem.Tag;
feature.Enabled = e.NewCheckState == true;
applyButton.Enabled = true;
};ItemHoverChanged
Occurs when the pointer moves onto an item that has a tool tip, and when it leaves the control.
Remarks
Raised as the pointer reaches an item whose CheckedImageListBoxItem.TooltipContent is set
and differs from the tip already showing; items without tool tip text do not raise it. On leaving the
control it is raised with a CheckedImageListBoxItemHoverChangedEventArgs.HoveredItemIndex of
-1.
Not raised while IsReadOnly is on or SelectionMode is
None, apart from the leaving notification.
ItemImageClicked
Occurs when the user clicks an item's image.
Remarks
The event carries no data: the item is the one under the pointer, for example
IndexFromPoint(PointToClient(Cursor.Position)). In the collapsed view only an open row's image
counts. Not raised while
IsReadOnly is on, or when SelectionMode is
None.
ItemTooltipAboutToDraw
Occurs when an item's tool tip is about to be drawn, so that you can draw it yourself.
Remarks
While this event has a handler, the control draws nothing in the tool tip: draw the whole tip with
CheckedImageListBoxTooltipDrawEventArgs.DrawTooltipEventArgs. Raised only for
CheckedImageListBoxItem rows with CheckedImageListBoxItem.TooltipContent.
Handle it together with ItemTooltipAboutToPopup, which sizes the tip.
Example
taskList.ItemTooltipAboutToPopup += (sender, e) =>
e.TooltipPopupEventArgs.ToolTipSize = new Size(260, 56);
taskList.ItemTooltipAboutToDraw += (sender, e) =>
{
var draw = e.DrawTooltipEventArgs;
draw.Graphics.FillRectangle(Brushes.LightYellow, draw.Bounds);
draw.Graphics.DrawRectangle(Pens.Goldenrod, 0, 0, draw.Bounds.Width - 1, draw.Bounds.Height - 1);
TextRenderer.DrawText(draw.Graphics, e.CurrentlyHoveredListBoxItem.Title, taskList.ItemTitleFont,
new Point(8, 8), Color.Black);
TextRenderer.DrawText(draw.Graphics, e.CurrentlyHoveredListBoxItem.TooltipContent, taskList.Font,
new Point(8, 30), Color.DimGray);
};ItemTooltipAboutToPopup
Occurs when an item's tool tip is about to appear, so that you can size it or cancel it.
Remarks
While this event has a handler, the control does not size the tip itself: set
ToolTipSize on CheckedImageListBoxItemTooltipPopupEventArgs.TooltipPopupEventArgs, or
set Cancel to show nothing. Raised only for CheckedImageListBoxItem rows with
CheckedImageListBoxItem.TooltipContent.
Handle it together with ItemTooltipAboutToDraw: the control draws its own tip only when
neither is handled and ShouldShowDefaultTooltipOnItemHover is on.
VerticalScroll
Occurs when the list scrolls through the mouse wheel, the keyboard or ScrollIntoView.
Remarks
The handler's EventArgs is a CheckedImageListBoxVerticalScrollEventArgs; cast
it to read the scroll-bar positions before and after, the Windows message that caused the scroll and, for
a key, which key.
The ScrollEventType is EndScroll for the wheel, ThumbPosition for
ScrollIntoView, and for keys SmallDecrement (Up), SmallIncrement (Down),
LargeDecrement (Page Up), LargeIncrement (Page Down), First (Home) and Last
(End), as for a standard scroll bar.
Raised only when the top item actually changes, and not when the scroll bar itself is dragged or clicked.
Example
messageList.VerticalScroll += (sender, e) =>
{
var args = (CheckedImageListBoxVerticalScrollEventArgs)e;
if (args.ScrollEventArgs.Type == ScrollEventType.Last)
{
loadOlderMessagesButton.Visible = true;
}
};