HypernovaDesktop Components · docs
Binarymission
WinForms › Checked Image List Box › CheckedImageListBox

CheckedImageListBox

class.NET 6 / 8 / 10.NET Framework 4.8Binarymission.WinForms.Controls.ListControls

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.

Tip

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
CheckedImageListBoxInitialises an empty list in single selection, full view, with item borders, warm gradient colours and check boxes allowed.
Properties
AnnotationImageOnMouseHoverGets or sets the image shown at the right end of the item under the pointer.
CheckBoxSizeGets or sets the space reserved for an item's check box, and the size of a classic check box.
CheckOnClickGets or sets whether a single click on an item toggles its check box.
CheckedStateImageGets or sets the image shown for a checked item when check states are drawn as images.
ContentStringFormatGets or sets how an item's content text is aligned, wrapped and trimmed.
CreateParamsGets the window's creation parameters; while ShouldDrawFrame is on, without the border styles ListBox.BorderStyle asks for, since the frame replaces them.
DrawModeGets the drawing mode, which is always OwnerDrawVariable: the control measures and draws every row itself.
EnableItemFullViewGets or sets whether every row shows its content text, or only the selected rows (the collapsed view).
FrameBorderColorGets or sets the colour of the frame's border (see ShouldDrawFrame).
FrameBorderThicknessGets or sets the thickness of the frame's border, in logical (96 DPI) pixels, 0 to 8.
FrameCornerRadiusGets or sets the radius of the frame's corners, in logical (96 DPI) pixels, 0 to 32.
FrameFocusedBorderColorGets or sets the colour of the frame's border while the control has the focus. Color.Empty keeps FrameBorderColor.
FramePaddingGets 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.
FrameShadowColorGets or sets the colour of the frame's drop shadow. Its strength is FrameShadowOpacity, so the colour's own alpha is not used.
FrameShadowDepthGets 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.
FrameShadowOpacityGets or sets the strength of the frame's shadow at its darkest, as a percentage, 0 to 100.
IsAnnotationEnabledGets or sets whether AnnotationImageOnMouseHover is shown at the right end of the item under the pointer.
IsChildOfPopupWindowGets or sets whether the list is shown inside a popup or drop-down window.
IsImageDrawnWhenUsingDefaultItemTooltipGets or sets whether the control's own tool tip shows an information icon beside its title.
IsItemCheckUncheckAllowedGets or sets whether items show check boxes and can be checked.
IsItemSidebarBorderDrawingEnabledGets or sets whether the sidebar strip (see IsItemSidebarDrawingEnabled) has an outline.
IsItemSidebarDrawingEnabledGets or sets whether a coloured strip is drawn down the left of the selected item and of the item under the pointer.
IsReadOnlyGets or sets whether the list is for looking only: it can be scrolled, but not selected or checked.
ItemAlternateEndColorGets or sets the second colour of the background gradient of every second unselected item.
ItemAlternateGradientFactorGets or sets the direction of every unselected item's gradient while alternating colours are on.
ItemAlternateStartColorGets or sets the first colour of the background gradient of every second unselected item.
ItemContentFontGets or sets the font of every item's content text.
ItemContentTextColorGets or sets the content text colour of a selected item.
ItemDisabledContentTextColorGets or sets the colour of the items' content text while the control is disabled.
ItemDisabledEndColorGets or sets a second background colour for a disabled control, which the drawing does not use.
ItemDisabledStartColorGets or sets the first colour of every item's background gradient, and the border colour, while the control is disabled.
ItemDisabledTitleTextColorGets or sets the colour of the items' titles while the control is disabled.
ItemMouseHoverBorderColorGets or sets the border colour of the unselected item under the pointer.
ItemMouseHoverBorderThicknessGets or sets the width of the border of the item under the pointer.
ItemMouseHoverContentTextForeColorGets or sets the content text colour of the unselected item under the pointer.
ItemMouseHoverEndColorGets or sets the second colour of the background gradient of the unselected item under the pointer.
ItemMouseHoverGradientFactorGets or sets the direction of the background gradient of the unselected item under the pointer.
ItemMouseHoverStartColorGets or sets the first colour of the background gradient of the unselected item under the pointer.
ItemMouseHoverTitleForeColorGets or sets the title colour of the unselected item under the pointer.
ItemReadOnlyBorderColorGets or sets every item's border colour while IsReadOnly is on or SelectionMode is None.
ItemReadOnlyContentTextColorGets or sets the colour of every item's content text while IsReadOnly is on.
ItemReadOnlyEndColorGets or sets the second colour of every item's background gradient while IsReadOnly is on or SelectionMode is None.
ItemReadOnlyStartColorGets or sets the first colour of every item's background gradient while IsReadOnly is on or SelectionMode is None.
ItemReadOnlyTitleTextColorGets or sets the colour of every title while IsReadOnly is on.
ItemSelectedBorderColorGets or sets the border colour of a selected item.
ItemSelectedBorderThicknessGets or sets the width of a selected item's border.
ItemSelectedEndColorGets or sets the second colour of a selected item's background gradient.
ItemSelectedGradientFactorGets or sets the direction of a selected item's background gradient.
ItemSelectedStartColorGets or sets the first colour of a selected item's background gradient.
ItemSpacingGets or sets the gap left below each item.
ItemTitleFontGets or sets the font of every item's title.
ItemTitleTextColorGets or sets the title colour of a selected item.
ItemTooltipContentFontGets or sets the font of the tool tip text in the control's own tool tip.
ItemTooltipTitleFontGets or sets the font of the tool tip title in the control's own tool tip.
ItemUnselectedBorderColorGets or sets the border colour of an unselected item.
ItemUnselectedBorderThicknessGets or sets the width of the border of an unselected item.
ItemUnselectedContentTextColorGets or sets the content text colour of an unselected item.
ItemUnselectedEndColorGets or sets the second colour of an unselected item's background gradient.
ItemUnselectedGradientFactorGets or sets the direction of an unselected item's background gradient.
ItemUnselectedStartColorGets or sets the first colour of an unselected item's background gradient.
ItemUnselectedTitleTextColorGets or sets the title colour of an unselected item.
MinimumItemTopAndBottomMarginGets or sets the space kept above and below an item's content inside its row.
PaddingBetweenItemComponentsGets or sets the gap between the parts of an item: the edge, the check box, the image and the text.
SelectionModeGets or sets how many items can be selected at once, and how.
ShouldAnimateItemImageGets or sets whether the selected item's image is lifted by one pixel, so it appears to rise when the item is selected.
ShouldDrawCheckBoxInVisualStyleGets or sets whether check boxes are drawn in the current Windows theme rather than the classic style.
ShouldDrawFrameGets 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.
ShouldDrawFrameShadowGets or sets a value indicating whether the frame casts a soft drop shadow.
ShouldDrawItemBorderGets or sets whether a border is drawn around each item.
ShouldDrawTopItemSpacingForFirstItemGets or sets whether a gap of ItemSpacing is left above the first item, as there is below every item.
ShouldEnableAlternatingColorsGets or sets whether every second unselected item (the second, fourth and so on) is drawn in the alternate colours, for a striped list.
ShouldExpandItemFullViewUponClickGets 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.
ShouldRefreshBasedOnMessageGets or sets how the control applies new row heights: by sending them to the list box window, or by recreating the window.
ShouldShowDefaultTooltipOnItemHoverGets 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.
ShouldUseImageForCheckStateGets or sets whether every item's check state is shown with CheckedStateImage and UncheckedStateImage instead of a check box.
SidebarBorderThicknessGets or sets the width of the sidebar strip's outline.
SidebarGradientModeGets or sets the direction of the sidebar strip's gradient.
SidebarItemHoveredStateBorderColorGets or sets the colour of the sidebar strip's outline on the item under the pointer.
SidebarItemHoveredStateEndColorGets or sets the second colour of the sidebar strip's gradient on the item under the pointer.
SidebarItemHoveredStateStartColorGets or sets the first colour of the sidebar strip's gradient on the item under the pointer.
SidebarItemSelectedStateBorderColorGets or sets the colour of the sidebar strip's outline on the selected item.
SidebarItemSelectedStateEndColorGets or sets the second colour of the sidebar strip's gradient on the selected item.
SidebarItemSelectedStateStartColorGets or sets the first colour of the sidebar strip's gradient on the selected item.
SidebarWidthGets or sets the width of the sidebar strip.
TitleStringFormatGets or sets how an item's title is aligned, wrapped and trimmed.
UncheckedStateImageGets or sets the image shown for an unchecked item when check states are drawn as images.
Methods
DefWndProcPasses 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.
OnDrawItemRaises ListBox.DrawItem and draws the row: background, border, sidebar, check box, image, title, content text and annotation image.
OnHandleCreatedRaises Control.HandleCreated, then puts back the height the list was given.
OnKeyDownRaises 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.
OnKeyUpRaises Control.KeyUp; Space then toggles the selected item's check box and raises ItemCheckStateChanged.
OnMeasureItemRaises 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.
OnMouseDownRaises Control.MouseDown and notes the item pressed, which the release then checks or selects.
OnMouseLeaveRaises Control.MouseLeave, hides the tool tip and raises ItemHoverChanged with no item.
OnMouseMoveRaises Control.MouseMove and tracks the hovered item: its highlight, its tool tip and ItemHoverChanged.
OnMouseUpRaises Control.MouseUp, then completes a click: ItemImageClicked or AnnotationImageClicked when the image was hit, the check toggle (see CheckOnClick) and the selection.
OnMouseWheelRaises Control.MouseWheel; the list scrolls in the usual way.
OnPaintRaises Control.Paint, fills the background with Control.BackColor and draws every visible row.
OnResizeRaises Control.Resize and measures every item again for the new width, since text wraps differently.
OnSelectedIndexChangedRaises ListBox.SelectedIndexChanged and re-measures the rows whose view changes with the selection.
PerformDeterministicRefreshMeasures every item again and applies the new heights, without repainting.
PerformRefreshMeasurePaintMeasures every item again and repaints the list, keeping the same item at the top.
ProcessCmdKeyHandles 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.
ScrollIntoViewScrolls the list so that an item is at the top, and optionally selects it.
SelectAllSelects every item, as Ctrl+A does, and scrolls back to the first.
SetBoundsCorePerforms the work of setting the bounds of this control, remembering the height asked for.
SetCheckStateChecks, unchecks or removes the check box of one item, or of every item.
UnselectAllClears the selection and selects the first item.
WndProcProcesses 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
AnnotationImageClickedOccurs when the user clicks the annotation image shown at the right of the hovered item.
ItemCheckStateChangedOccurs when an item's check box is toggled: by a click, by the Space key, or by SetCheckState for one item.
ItemHoverChangedOccurs when the pointer moves onto an item that has a tool tip, and when it leaves the control.
ItemImageClickedOccurs when the user clicks an item's image.
ItemTooltipAboutToDrawOccurs when an item's tool tip is about to be drawn, so that you can draw it yourself.
ItemTooltipAboutToPopupOccurs when an item's tool tip is about to appear, so that you can size it or cancel it.
VerticalScrollOccurs when the list scrolls through the mouse wheel, the keyboard or ScrollIntoView.

Constructors

CheckedImageListBox

public CheckedImageListBox()

Initialises an empty list in single selection, full view, with item borders, warm gradient colours and check boxes allowed.

Properties

AnnotationImageOnMouseHover

public Image 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

public Size 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

public bool 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

public Image 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

public StringFormat 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

protected override CreateParams 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

public override DrawMode 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

public bool 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

public Color 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

public int 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

public int 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

public Color 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

public int 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

public Color 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

public int 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

public int 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

public bool 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

public bool 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

public bool 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

public bool 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

public bool IsItemSidebarBorderDrawingEnabled

Gets or sets whether the sidebar strip (see IsItemSidebarDrawingEnabled) has an outline.

Value
The default is false.

IsItemSidebarDrawingEnabled

public bool 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

public bool 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

public Color 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

public float 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

public Color 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

public Font ItemContentFont

Gets or sets the font of every item's content text.

Value
By default the control's Control.Font when it was created. An item's own CheckedImageListBoxItem.ContentTextFont overrides it.

ItemContentTextColor

public Color 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

public Color ItemDisabledContentTextColor

Gets or sets the colour of the items' content text while the control is disabled.

Value
The default is SystemColors.GrayText.
Remarks

ItemDisabledEndColor

public Color 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

public Color 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

public Color 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

public Color ItemMouseHoverBorderColor

Gets or sets the border colour of the unselected item under the pointer.

Value
The default is Color.DarkBlue.

ItemMouseHoverBorderThickness

public int 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

public Color ItemMouseHoverContentTextForeColor

Gets or sets the content text colour of the unselected item under the pointer.

Value
The default is Color.Blue.

ItemMouseHoverEndColor

public Color 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

public float 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

public Color 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

public Color ItemMouseHoverTitleForeColor

Gets or sets the title colour of the unselected item under the pointer.

Value
The default is Color.BlueViolet.

ItemReadOnlyBorderColor

public Color ItemReadOnlyBorderColor

Gets or sets every item's border colour while IsReadOnly is on or SelectionMode is None.

Value
The default is Color.Black.

ItemReadOnlyContentTextColor

public Color ItemReadOnlyContentTextColor

Gets or sets the colour of every item's content text while IsReadOnly is on.

Value
The default is Color.Black.
Remarks

ItemReadOnlyEndColor

public Color 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

public Color 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

public Color 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

public Color ItemSelectedBorderColor

Gets or sets the border colour of a selected item.

Value
The default is Color.Red.

ItemSelectedBorderThickness

public int ItemSelectedBorderThickness

Gets or sets the width of a selected item's border.

Value
In logical pixels. The default is 1.

ItemSelectedEndColor

public Color ItemSelectedEndColor

Gets or sets the second colour of a selected item's background gradient.

Value
The default is Color.White.

ItemSelectedGradientFactor

public float 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

public Color ItemSelectedStartColor

Gets or sets the first colour of a selected item's background gradient.

Value
The default is Color.LightSalmon.

ItemSpacing

public int 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

public Font 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.TitleFont overrides it.

ItemTitleTextColor

public Color 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

public Font 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.Font when it was created.
See also

ItemTooltipTitleFont

public Font 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

public Color 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

public int 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.BorderThickness overrides it.

ItemUnselectedContentTextColor

public Color 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

public Color 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

public float 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

public Color ItemUnselectedStartColor

Gets or sets the first colour of an unselected item's background gradient.

Value
The default is Color.NavajoWhite.
Remarks

ItemUnselectedTitleTextColor

public Color 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

public int 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

public int 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

public override SelectionMode 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

public bool 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

public bool 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

public bool 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

public bool ShouldDrawFrameShadow

Gets or sets a value indicating whether the frame casts a soft drop shadow.

Value
The default is true. Drawn only while ShouldDrawFrame is on.
Default
true

ShouldDrawItemBorder

public bool 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

public bool 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

public bool 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

public bool 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

public bool 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; false to recreate the window, which re-measures everything but is slower and can flicker.

ShouldShowDefaultTooltipOnItemHover

public bool 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 handle ItemTooltipAboutToPopup and ItemTooltipAboutToDraw.
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

public bool 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 own CheckedImageListBoxItem.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

public int 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

public LinearGradientMode SidebarGradientMode

Gets or sets the direction of the sidebar strip's gradient.

Value
The default is Horizontal.

SidebarItemHoveredStateBorderColor

public Color 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

public Color 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

public Color 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

public Color SidebarItemSelectedStateBorderColor

Gets or sets the colour of the sidebar strip's outline on the selected item.

Value
The default is Color.Black.

SidebarItemSelectedStateEndColor

public Color SidebarItemSelectedStateEndColor

Gets or sets the second colour of the sidebar strip's gradient on the selected item.

Value
The default is Color.BurlyWood.

SidebarItemSelectedStateStartColor

public Color SidebarItemSelectedStateStartColor

Gets or sets the first colour of the sidebar strip's gradient on the selected item.

Value
The default is Color.Brown.

SidebarWidth

public int SidebarWidth

Gets or sets the width of the sidebar strip.

Value
In logical pixels. The default is 12; 0 draws no strip.

TitleStringFormat

public StringFormat 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

public Image 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

protected override void DefWndProc(ref Message m)

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

protected override void OnDrawItem(DrawItemEventArgs e)

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

protected override void OnHandleCreated(EventArgs e)

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

protected override void OnKeyDown(KeyEventArgs e)

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

protected override void OnKeyUp(KeyEventArgs e)

Raises Control.KeyUp; Space then toggles the selected item's check box and raises ItemCheckStateChanged.

Parameters
e
The key data.

OnMeasureItem

protected override void OnMeasureItem(MeasureItemEventArgs e)

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

protected override void OnMouseDown(MouseEventArgs e)

Raises Control.MouseDown and notes the item pressed, which the release then checks or selects.

Parameters
e
The mouse data.

OnMouseLeave

protected override void OnMouseLeave(EventArgs e)

Raises Control.MouseLeave, hides the tool tip and raises ItemHoverChanged with no item.

Parameters
e
The event data.

OnMouseMove

protected override void OnMouseMove(MouseEventArgs e)

Raises Control.MouseMove and tracks the hovered item: its highlight, its tool tip and ItemHoverChanged.

Parameters
e
The mouse data.

OnMouseUp

protected override void OnMouseUp(MouseEventArgs e)

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

protected override void OnMouseWheel(MouseEventArgs e)

Raises Control.MouseWheel; the list scrolls in the usual way.

Parameters
e
The wheel data.

OnPaint

protected override void OnPaint(PaintEventArgs e)

Raises Control.Paint, fills the background with Control.BackColor and draws every visible row.

Parameters
e
The paint data.

OnResize

protected override void OnResize(EventArgs e)

Raises Control.Resize and measures every item again for the new width, since text wraps differently.

Parameters
e
The event data.

OnSelectedIndexChanged

protected override void OnSelectedIndexChanged(EventArgs e)

Raises ListBox.SelectedIndexChanged and re-measures the rows whose view changes with the selection.

Parameters
e
The event data.

PerformDeterministicRefresh

public void 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

public void 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

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)

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

public bool ScrollIntoView(int index, bool autoSelect)

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.
autoSelect
true to make it the ListBox.SelectedIndex as well (ignored when SelectionMode is None).
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

public void SelectAll()

Selects every item, as Ctrl+A does, and scrolls back to the first.

Remarks

Works only in the multiple selection modes; in One and None it does nothing. In the collapsed view every row opens.

SetBoundsCore

protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)

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

public void SetCheckState(int index

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.
isChecked
true (the default) to check, false to uncheck, null to 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 item

UnselectAll

public void UnselectAll()

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

protected override void WndProc(ref Message m)

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

public event EventHandler 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

public event EventHandler<CheckedImageListBoxItemCheckStateChangedEventArgs> 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

public event EventHandler<CheckedImageListBoxItemHoverChangedEventArgs> 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

public event EventHandler 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

public event EventHandler<CheckedImageListBoxTooltipDrawEventArgs> 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

public event EventHandler<CheckedImageListBoxItemTooltipPopupEventArgs> 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

public event EventHandler 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;
    }
};