HypernovaDesktop Components · docs
Binarymission
WinForms › Combo Box › BinaryComboBox

BinaryComboBox

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

The shared base of BinaryTextComboBox and BinaryImageComboBox: a Windows Forms combo box that draws its own flat border, drop-down button and items, in colours you choose.

public abstract partial class BinaryComboBox : System.Windows.Forms.ComboBox

Inherits from / implements: System.Windows.Forms.ComboBox

Remarks

What it is for

Everything the two Hypernova combo boxes have in common lives here: the colours of the border, the drop-down button and the highlighted item, how the border behaves when the pointer and the focus come and go, the optional push-button style drop-down button, the look of the single-column drop-down list, and the extended read-only mode. The class is abstract and is not in the Toolbox; place a BinaryTextComboBox (text, data binding, auto-completion, a multi-column drop-down) or a BinaryImageComboBox (an image beside each item, drive and font lists) on the form instead.

Colours

Two colours drive the whole look. CustomControlBorderColor is the border and the outline round the drop-down button. CustomPaintingColor is blended with the window colour to give the drop-down button face and the highlighted item, and blended again for the button while the list is open. The three alpha-blending factors (0 to 255) say how much of it goes into each blend: AlphaBlendFactorForItemSelectionColor, AlphaBlendFactorForDropDownPressedColor and AlphaBlendFactorForControlPainting. EmulateThisXPTheme sets all five at once to one of the Windows XP colour schemes.

The border

With ShowBorderAlways on (the default) the border is always drawn; CustomControlBorderColorWhenNotInFocus gives it a quieter colour while the control does not have the focus. With it off, the border appears only while the pointer is over the control or it has the focus.

Things to know

Examples

A text combo box in the application's accent colour, with a quiet grey border while it does not have the focus.

var statusPicker = new BinaryTextComboBox
{
    Location = new Point(12, 12),
    Width = 220,
    DropDownStyle = ComboBoxStyle.DropDownList,
};
statusPicker.Items.AddRange(new object[] { "Open", "In progress", "On hold", "Closed" });
statusPicker.SelectedIndex = 0;

statusPicker.CustomPaintingColor = Color.FromArgb(0, 120, 215);
statusPicker.CustomControlBorderColor = Color.FromArgb(0, 90, 158);
statusPicker.CustomControlBorderColorWhenNotInFocus = Color.Silver;
statusPicker.AlphaBlendFactorForItemSelectionColor = 90;   // a light tint for the highlighted item
statusPicker.ControlArrowColor = Color.FromArgb(0, 90, 158);

statusPicker.SelectedIndexChanged += (sender, e) => Text = "Status: " + statusPicker.SelectedItem;
Controls.Add(statusPicker);

See also

Members at a glance

Constructors
BinaryComboBoxSets up the owner-drawn, flat painting and the default colours shared by the Hypernova combo boxes.
Properties
AlphaBlendFactorForControlPaintingGets or sets the blend weight used for the background of the flat drop-down button's arrow area.
AlphaBlendFactorForDropDownPressedColorGets or sets how strongly CustomPaintingColor shows in the drop-down button while the list is open.
AlphaBlendFactorForItemSelectionColorGets or sets how strongly CustomPaintingColor shows in the highlighted item and the drop-down button face.
ControlArrowColorGets or sets the colour of the arrow (chevron) on the drop-down button.
CustomControlBorderColorGets or sets the colour of the control's border and of the outline round its drop-down button.
CustomControlBorderColorWhenNotInFocusGets or sets the colour of the border, and of the drop-down button, while the control does not have the focus.
CustomControlDropDownButtonFillColorWhenNotInFocusGets or sets the colour that fills the drop-down button while the control does not have the focus.
CustomPaintingColorGets or sets the accent colour the control blends to fill its drop-down button and the highlighted item.
DropDownItemBorderColorGets or sets the colour of the rectangle drawn round each item in the single-column drop-down list.
DropDownItemTextAlignmentGets or sets how the item text is aligned in the drop-down list.
DropDownStyleGets or sets whether the user can type into the control (DropDown) or can only pick from the list (DropDownList).
DropDownWindowBackgroundColorGets or sets the background colour of the single-column drop-down list.
DropDownWindowBorderColorGets or sets the colour of the border drawn round the single-column drop-down list.
DropDownWindowBorderThicknessGets or sets the width of the border drawn round the single-column drop-down list.
ExtendedDropdownButtonImageGets or sets a picture that replaces the whole push-button style drop-down button.
ExtendedDropdownButtonInternalImageGets or sets the small arrow image drawn on the push-button style drop-down button, in place of the built-in arrow.
IsInExtendedReadOnlyModeGets or sets whether a read-only text combo box also refuses changes to its selection, not just to its text.
MultiColumnDropDownWindowBorderThicknessGets or sets the width of the frame round the multi-column drop-down when it shows a header and footer.
MultiColumnWindowColumnsHorizontalAlignmentsGets or sets the alignment of each column in the multi-column drop-down, in column order.
ReflectCurrentXPThemeColorOnLoadGets or sets whether the control takes its colours from the current Windows colour scheme when its window is created.
RightToLeftGets the control's right-to-left setting, which is always No: right-to-left layout is not supported.
ShouldApplyMultiColumnWindowColumnsAlignmentsToAutoCompleteDropDownGets or sets whether the per-column alignments in MultiColumnWindowColumnsHorizontalAlignments are also applied to the multi-column suggestion list shown while the user types.
ShouldDisplayColumnHeadersWhenInMultiColumnModeGets or sets whether the multi-column drop-down shows its row of column headings.
ShouldDrawExtendedDropdownButtonGets or sets whether the drop-down button is drawn as a separate, push-button style button beside the text area, instead of the flat button inside the border.
ShowBorderAlwaysGets or sets whether the border is drawn all the time, or only while the pointer is over the control or it has the focus.
TextAlignmentGets or sets how the selected item's text is aligned on the closed control.
UpdateWhenSystemColorsChangesGets or sets whether the control applies the current Windows colour scheme again whenever the system colours change.
Methods
DropDownButtonExtentReturns the width of the drop-down button strip at the right of the control, in device pixels.
EmulateThisXPThemeColours the control to match one of the Windows XP colour schemes: Blue, Olive Green or Silver.
MakeBlankClears the selection, so the control shows no item.
MeasureTextViaGdiMeasures text the way GDI draws it, for laying out text that the control draws.
OnDrawItemDraws one item of the list, or the selected item on the closed control, by calling PaintControlWithData.
OnGotFocusRaises the Control.GotFocus event and redraws the border and drop-down button in their highlighted colours.
OnHandleCreatedPrepares the new window: turns off its visual style so the control's own drawing stays in place, applies the current Windows colour scheme when ReflectCurrentXPThemeColorOnLoad is set, and attaches to the edit box of a DropDown combo box so the border follows the pointer over it.
OnKeyPressRaises the Control.KeyPress event; an exception thrown by a handler is absorbed rather than propagated, so a faulty handler cannot close the form.
OnLostFocusRaises the Control.LostFocus event and redraws the border and drop-down button in their resting state.
OnMouseEnterRaises the Control.MouseEnter event and shows the border and drop-down button in their highlighted colours.
OnMouseLeaveRaises the Control.MouseLeave event and, unless the control has the focus, returns the border to its resting state: hidden with ShowBorderAlways off, or drawn in CustomControlBorderColorWhenNotInFocus when that is set.
OnPaintPaints the closed control when it draws itself – the face, the selected item and the border – in the colours set on the control.
OnSelectedIndexChangedRaises the ComboBox.SelectedIndexChanged event; an exception thrown by a handler is absorbed rather than propagated.
OnSystemColorsChangedRaises the Control.SystemColorsChanged event and, when UpdateWhenSystemColorsChanges is set, applies the colour scheme of the current Windows theme again.
PaintControlWithDataDraws one item, either in the drop-down list or as the selected item on the closed control.
RefreshPaintRedraws the selected item on the closed control, without waiting for a full repaint.
SetDataDraws the control in its disabled state: a plain face, a dark grey border and a dimmed drop-down button, with the selected item's text in the dimmed system colour.
WndProcProcesses Windows messages, redrawing the flat border and drop-down button after the control has painted itself.
Fields
DropDownButtonWidthThe width, in logical pixels, of the area the flat drop-down button's arrow is drawn in; it is 12.

Constructors

BinaryComboBox

public BinaryComboBox()

Sets up the owner-drawn, flat painting and the default colours shared by the Hypernova combo boxes.

Remarks

The defaults: CustomPaintingColor and CustomControlBorderColor are SystemColors.Highlight, ControlArrowColor is SystemColors.WindowText, ShowBorderAlways and ShouldDisplayColumnHeadersWhenInMultiColumnMode are true, the drop-down list's border and item borders are transparent, and the text is left-aligned.

Properties

AlphaBlendFactorForControlPainting

public int AlphaBlendFactorForControlPainting

Gets or sets the blend weight used for the background of the flat drop-down button's arrow area.

Value
A blend weight from 0 to 255 between SystemColors.Control (255) and a pale mix of the window and control colours (0). The default is 100.
Designer category
Color
Remarks

It does not involve CustomPaintingColor, so it changes only how grey the arrow area looks. EmulateThisXPTheme sets it to 100.

AlphaBlendFactorForDropDownPressedColor

public int AlphaBlendFactorForDropDownPressedColor

Gets or sets how strongly CustomPaintingColor shows in the drop-down button while the list is open.

Value
A blend weight from 0 to 255: 255 is CustomPaintingColor itself, 0 is the button's ordinary face colour. The default is 70.
Designer category
Color
Remarks

The pressed colour is CustomPaintingColor blended over the button's ordinary face (itself CustomPaintingColor blended with the window colour by AlphaBlendFactorForItemSelectionColor). EmulateThisXPTheme sets it to 75.

See also

AlphaBlendFactorForItemSelectionColor

public int AlphaBlendFactorForItemSelectionColor

Gets or sets how strongly CustomPaintingColor shows in the highlighted item and the drop-down button face.

Value
A blend weight from 0 to 255: 255 is CustomPaintingColor itself, 0 is SystemColors.Window. The default is 70, a light tint.
Designer category
Color
Remarks

The same colour fills the highlighted item, in the list and on the closed control, and the drop-down button while the list is closed, so the two always match. EmulateThisXPTheme sets it to 135.

See also

ControlArrowColor

public Color ControlArrowColor

Gets or sets the colour of the arrow (chevron) on the drop-down button.

Value
The arrow colour. The default is SystemColors.WindowText.
Remarks

The disabled control draws its arrow in SystemColors.ControlDark whatever this is set to. With ShouldDrawExtendedDropdownButton on, the built-in arrow image is recoloured to this colour; an image of your own in ExtendedDropdownButtonInternalImage is drawn as it is.

CustomControlBorderColor

public Color CustomControlBorderColor

Gets or sets the colour of the control's border and of the outline round its drop-down button.

Value
The border colour. The default is SystemColors.Highlight.
Designer category
Color
Remarks

The border is drawn in this colour whenever it is shown – always, with ShowBorderAlways on, or while the pointer is over the control or it has the focus, with it off. To use a different colour while the control does not have the focus, set CustomControlBorderColorWhenNotInFocus.

EmulateThisXPTheme replaces the value.

See also

CustomControlBorderColorWhenNotInFocus

public Color CustomControlBorderColorWhenNotInFocus

Gets or sets the colour of the border, and of the drop-down button, while the control does not have the focus.

Value
The resting border colour, or Color.Transparent to use CustomControlBorderColor all the time. The default is Color.Transparent.
Designer category
Color
Remarks

Used only while ShowBorderAlways is true, and not in the designer. When the control gets the focus, or the pointer moves over it, the border goes back to CustomControlBorderColor.

The drop-down button is filled with this colour too, unless CustomControlDropDownButtonFillColorWhenNotInFocus gives it one of its own.

Example
// Grey until the user arrives, then the accent colour.
customerPicker.ShowBorderAlways = true;
customerPicker.CustomControlBorderColor = Color.SteelBlue;
customerPicker.CustomControlBorderColorWhenNotInFocus = Color.Gainsboro;
customerPicker.CustomControlDropDownButtonFillColorWhenNotInFocus = Color.WhiteSmoke;

CustomControlDropDownButtonFillColorWhenNotInFocus

public Color CustomControlDropDownButtonFillColorWhenNotInFocus

Gets or sets the colour that fills the drop-down button while the control does not have the focus.

Value
The resting button colour, or Color.Transparent to fill the button with CustomControlBorderColorWhenNotInFocus. The default is Color.Transparent.
Designer category
Color
Remarks

Used only when CustomControlBorderColorWhenNotInFocus is set and ShowBorderAlways is true. The control does not repaint when it changes; set it before the control is shown, or call Control.Invalidate.

CustomPaintingColor

public Color CustomPaintingColor

Gets or sets the accent colour the control blends to fill its drop-down button and the highlighted item.

Value
The accent colour. The default is SystemColors.Highlight.
Designer category
Color
Remarks

The colour is not used as it stands. It is blended with SystemColors.Window by AlphaBlendFactorForItemSelectionColor to fill the drop-down button and the highlighted item, and blended again by AlphaBlendFactorForDropDownPressedColor for the button while the list is open. Lower factors give paler tints.

EmulateThisXPTheme replaces the value.

See also

DropDownItemBorderColor

public Color DropDownItemBorderColor

Gets or sets the colour of the rectangle drawn round each item in the single-column drop-down list.

Value
The item border colour. The default is Color.Transparent, which draws none.
Remarks

One pixel wide; a coloured value gives the list a ruled, table-like look. The multi-column drop-down uses BinaryTextComboBox.MultiColumnDropListGridLines instead.

See also

DropDownItemTextAlignment

public HorizontalAlignment DropDownItemTextAlignment

Gets or sets how the item text is aligned in the drop-down list.

Value
One of the HorizontalAlignment values. The default is HorizontalAlignment.Left.
Remarks

In the single-column list of BinaryTextComboBox it applies to items that come from a DataSource; items added to ComboBox.Items are drawn left-aligned.

In the multi-column drop-down it aligns every column and its heading; a column given its own alignment in MultiColumnWindowColumnsHorizontalAlignments uses that instead.

See also

DropDownStyle

public new ComboBoxStyle DropDownStyle

Gets or sets whether the user can type into the control (DropDown) or can only pick from the list (DropDownList).

Value
One of the ComboBoxStyle values other than Simple. The default depends on the derived control: DropDown for BinaryTextComboBox, DropDownList for BinaryImageComboBox.
Remarks

Simple is not supported: setting it is ignored and the style stays as it was.

DropDownWindowBackgroundColor

public Color DropDownWindowBackgroundColor

Gets or sets the background colour of the single-column drop-down list.

Value
The list's background colour. The default is SystemColors.Window.
Remarks

BinaryTextComboBox hides this property with its own, which also sets the background of the multi-column drop-down.

DropDownWindowBorderColor

public Color DropDownWindowBorderColor

Gets or sets the colour of the border drawn round the single-column drop-down list.

Value
The border colour. The default is Color.Transparent, which draws no border.
Remarks

The border is drawn DropDownWindowBorderThickness wide, along the outer edges of the list's items, and only while the list has items. The multi-column drop-down of BinaryTextComboBox draws its own frame and does not use it.

See also

DropDownWindowBorderThickness

public float DropDownWindowBorderThickness

Gets or sets the width of the border drawn round the single-column drop-down list.

Value
The pen width, in pixels. The default is 1.
Remarks

Used only when DropDownWindowBorderColor is not transparent. The width is applied as given and is not scaled to the display.

ExtendedDropdownButtonImage

public Bitmap ExtendedDropdownButtonImage

Gets or sets a picture that replaces the whole push-button style drop-down button.

Value
The button picture, or null to draw the themed push button. The default is null.
Remarks

Used only while ShouldDrawExtendedDropdownButton is true. The picture is stretched over the button's whole area – DropDownButtonExtent wide and the control's height – and drawn as it is, with no arrow added; draw the arrow into the picture. The same picture is used when the control is disabled.

ExtendedDropdownButtonInternalImage

public Bitmap ExtendedDropdownButtonInternalImage

Gets or sets the small arrow image drawn on the push-button style drop-down button, in place of the built-in arrow.

Value
The arrow image, or null for the built-in arrow. The default is null.
Remarks

Used only while ShouldDrawExtendedDropdownButton is true and ExtendedDropdownButtonImage is null. The image is drawn into a 6 by 6 pixel box, centred vertically on the button and not scaled to the display, and is not recoloured to ControlArrowColor.

IsInExtendedReadOnlyMode

public bool IsInExtendedReadOnlyMode

Gets or sets whether a read-only text combo box also refuses changes to its selection, not just to its text.

Value
true to lock the selection as well as the text. The default is false.
Remarks

This works together with BinaryTextComboBox.ComboBoxIsReadOnly, and only while that is true. A read-only combo box on its own refuses typing, Delete and Backspace but still lets the user pick another item. In extended read-only mode it also ignores every key in its text area, puts back the previous item when the user picks one from the drop-down list, and does not let the selection move in the multi-column drop-down. The user can still open the list and look.

BinaryImageComboBox has no read-only mode, so the property has no effect there.

Example
// Show the account's region, but do not let it be changed on this screen.
regionPicker.ComboBoxIsReadOnly = true;
regionPicker.IsInExtendedReadOnlyMode = true;
See also

MultiColumnDropDownWindowBorderThickness

public float MultiColumnDropDownWindowBorderThickness

Gets or sets the width of the frame round the multi-column drop-down when it shows a header and footer.

Value
The width in logical pixels, scaled to the display. Values under 2, including the default 0, draw a frame 2 wide.
Remarks

The frame belongs to the header and footer area, so it is drawn only while BinaryTextComboBox.EnableDrawingHeaderFooterWhenInMultiColumnMode is true, in the colour of MultiColumnDropDownWindowConfiguration.HeaderControlRenderingStartColor.

MultiColumnWindowColumnsHorizontalAlignments

public IList<HorizontalAlignment> MultiColumnWindowColumnsHorizontalAlignments

Gets or sets the alignment of each column in the multi-column drop-down, in column order.

Value
One alignment per column, the first for the first column shown. BinaryTextComboBox starts with an empty list; the base class leaves it null.
Remarks

The first entry aligns the first column and its heading, the second the second, and so on. Columns beyond the end of the list keep DropDownItemTextAlignment. Change the list itself, or assign a new one; do not assign null on a BinaryTextComboBox, which expects a list when it opens the drop-down.

With ShouldApplyMultiColumnWindowColumnsAlignmentsToAutoCompleteDropDown on, the typing suggestion list follows the same alignments.

Example
// Account and customer on the left, the balance on the right.
accountPicker.ColumnsToDisplay = new[] { "AccountNo", "Name", "Balance" };
accountPicker.MultiColumnWindowColumnsHorizontalAlignments = new List<HorizontalAlignment>
{
    HorizontalAlignment.Left, HorizontalAlignment.Left, HorizontalAlignment.Right
};

ReflectCurrentXPThemeColorOnLoad

public bool ReflectCurrentXPThemeColorOnLoad

Gets or sets whether the control takes its colours from the current Windows colour scheme when its window is created.

Value
true to apply the matching scheme when the window is created. The default is false.
Default
false
Remarks

The control reads the name of the current visual style's colour scheme and calls EmulateThisXPTheme: Olive Green for the XP "HomeStead" scheme, Silver for "Metallic", and Blue for any other – which on current versions of Windows means Blue. The colours you set yourself for the five properties that method sets are overwritten when the window is created.

Applies only while the control uses its flat drawing.

See also

RightToLeft

public override RightToLeft RightToLeft

Gets the control's right-to-left setting, which is always No: right-to-left layout is not supported.

Value
No. Setting any value sets No.

ShouldApplyMultiColumnWindowColumnsAlignmentsToAutoCompleteDropDown

public bool ShouldApplyMultiColumnWindowColumnsAlignmentsToAutoCompleteDropDown

Gets or sets whether the per-column alignments in MultiColumnWindowColumnsHorizontalAlignments are also applied to the multi-column suggestion list shown while the user types.

Value
true to align the suggestion list's columns the same way. The default is false.
Remarks

ShouldDisplayColumnHeadersWhenInMultiColumnMode

public bool ShouldDisplayColumnHeadersWhenInMultiColumnMode

Gets or sets whether the multi-column drop-down shows its row of column headings.

Value
true to show the headings. The default is true.
Remarks

Without headings the user cannot sort by clicking a column, whatever BinaryTextComboBox.EnableColumnSorting says. The heading text comes from BinaryTextComboBox.HeadersToDisplay, or from the column names.

ShouldDrawExtendedDropdownButton

public bool ShouldDrawExtendedDropdownButton

Gets or sets whether the drop-down button is drawn as a separate, push-button style button beside the text area, instead of the flat button inside the border.

Value
true for the push-button style. The default is false.
Remarks

The button is drawn with the Windows visual style for a push button, as wide as DropDownButtonExtent and outside the border, with a small arrow image on it: the built-in arrow recoloured to ControlArrowColor, or ExtendedDropdownButtonInternalImage if you set one. To draw the whole button from a picture of your own, set ExtendedDropdownButtonImage.

The space round the button is filled with the parent's background colour, read when the control's window is created.

Example
departmentPicker.ShouldDrawExtendedDropdownButton = true;
departmentPicker.ControlArrowColor = Color.DarkSlateGray;
See also

ShowBorderAlways

public bool ShowBorderAlways

Gets or sets whether the border is drawn all the time, or only while the pointer is over the control or it has the focus.

Value
true to draw the border all the time. The default is true.
Remarks

With it on, the border is drawn in CustomControlBorderColor, or in CustomControlBorderColorWhenNotInFocus while the control does not have the focus if that is set. With it off, the control rests without a visible border, which appears when the pointer arrives or the control gets the focus – the hover look of a toolbar control.

TextAlignment

public HorizontalAlignment TextAlignment

Gets or sets how the selected item's text is aligned on the closed control.

Value
One of the HorizontalAlignment values. The default is HorizontalAlignment.Left.
Remarks

Only a DropDownList combo box draws its own text, so only it can align it. In DropDown style the value is always HorizontalAlignment.Left: setting another is ignored, and switching to that style puts it back to left.

BinaryTextComboBox uses it. The items in the drop-down list are aligned by DropDownItemTextAlignment.

UpdateWhenSystemColorsChanges

public bool UpdateWhenSystemColorsChanges

Gets or sets whether the control applies the current Windows colour scheme again whenever the system colours change.

Value
true to follow changes to the system colours. The default is false.
Default
false
Remarks

When the user changes the Windows colours, the control picks the matching scheme exactly as ReflectCurrentXPThemeColorOnLoad does, overwriting the colours set on it.

Methods

DropDownButtonExtent

protected internal int DropDownButtonExtent()

Returns the width of the drop-down button strip at the right of the control, in device pixels.

Returns

The larger of the system's vertical scroll bar width and one and a quarter times the height of the control's Control.Font.

Remarks

The button grows with the font, so a combo box given a large font keeps a button in proportion to its text. Every part of the control that needs the button's width reads it here, so the button, the text area beside it and the drop-down's position stay in agreement.

EmulateThisXPTheme

public void EmulateThisXPTheme(XPTheme theTheme)

Colours the control to match one of the Windows XP colour schemes: Blue, Olive Green or Silver.

Parameters
theTheme
The colour scheme to match.
Remarks

The control is still drawn by its own flat painting; only the colours change. CustomControlBorderColor becomes blue, olive or dark grey, CustomPaintingColor becomes the scheme's Explorer bar colour, and the alpha-blending factors become 100 (AlphaBlendFactorForControlPainting), 75 (AlphaBlendFactorForDropDownPressedColor) and 135 (AlphaBlendFactorForItemSelectionColor).

The values you had set for those five properties are overwritten. Keep them first if you want to go back to them later, and set them again yourself; any value set after the call is used as it is.

Example
productPicker.EmulateThisXPTheme(XPTheme.Silver);
See also

MakeBlank

public void MakeBlank()

Clears the selection, so the control shows no item.

Remarks

ComboBox.SelectedIndex becomes -1 and the text area is emptied. The control sets it twice, because a single assignment does not always clear a Windows combo box.

Example
private void clearButton_Click(object sender, EventArgs e)
{
    customerPicker.MakeBlank();
    orderNumberBox.Clear();
}

MeasureTextViaGdi static

protected static Size MeasureTextViaGdi(Graphics graphics, string text, Font font)

Measures text the way GDI draws it, for laying out text that the control draws.

Parameters
graphics
The surface the text will be drawn on.
text
The text to measure.
font
The font it will be drawn in.
Returns

The width and height the text occupies on a single line, in device pixels; an empty size if it cannot be measured.

Remarks

GDI and GDI+ (Graphics.MeasureString) measure the same text differently. A derived control centring text vertically in an item uses this so its rows line up with the built-in ones.

OnDrawItem

protected override void OnDrawItem(DrawItemEventArgs e)

Draws one item of the list, or the selected item on the closed control, by calling PaintControlWithData.

Parameters
e
The item to draw, its bounds and its state.

OnGotFocus

protected override void OnGotFocus(EventArgs e)

Raises the Control.GotFocus event and redraws the border and drop-down button in their highlighted colours.

Parameters
e
The event data.

OnHandleCreated

protected override void OnHandleCreated(EventArgs e)

Prepares the new window: turns off its visual style so the control's own drawing stays in place, applies the current Windows colour scheme when ReflectCurrentXPThemeColorOnLoad is set, and attaches to the edit box of a DropDown combo box so the border follows the pointer over it.

Parameters
e
The event data.

OnKeyPress

protected override void OnKeyPress(KeyPressEventArgs e)

Raises the Control.KeyPress event; an exception thrown by a handler is absorbed rather than propagated, so a faulty handler cannot close the form.

Parameters
e
The key that was pressed.

OnLostFocus

protected override void OnLostFocus(EventArgs e)

Raises the Control.LostFocus event and redraws the border and drop-down button in their resting state.

Parameters
e
The event data.

OnMouseEnter

protected override void OnMouseEnter(EventArgs e)

Raises the Control.MouseEnter event and shows the border and drop-down button in their highlighted colours.

Parameters
e
The event data.

OnMouseLeave

protected override void OnMouseLeave(EventArgs e)

Raises the Control.MouseLeave event and, unless the control has the focus, returns the border to its resting state: hidden with ShowBorderAlways off, or drawn in CustomControlBorderColorWhenNotInFocus when that is set.

Parameters
e
The event data.

OnPaint

protected override void OnPaint(PaintEventArgs pe)

Paints the closed control when it draws itself – the face, the selected item and the border – in the colours set on the control.

Parameters
pe
The paint data.
Remarks

A combo box in DropDown style leaves its face to its edit box, and a disabled one is drawn greyed by SetData.

OnSelectedIndexChanged

protected override void OnSelectedIndexChanged(EventArgs e)

Raises the ComboBox.SelectedIndexChanged event; an exception thrown by a handler is absorbed rather than propagated.

Parameters
e
The event data.

OnSystemColorsChanged

protected override void OnSystemColorsChanged(EventArgs e)

Raises the Control.SystemColorsChanged event and, when UpdateWhenSystemColorsChanges is set, applies the colour scheme of the current Windows theme again.

Parameters
e
The event data.

PaintControlWithData

protected virtual void PaintControlWithData(Graphics g, Rectangle bounds, int Index, bool isSelected, bool toEdit)

Draws one item, either in the drop-down list or as the selected item on the closed control.

Parameters
g
The surface to draw on.
bounds
The item's bounds, in device pixels.
Index
The index of the item in the list.
isSelected
true when the item is the highlighted one.
toEdit
true when the item is being drawn on the closed control rather than in the list.
Remarks

The base fills the background – the highlight colour for the highlighted item, otherwise DropDownWindowBackgroundColor in the open list – and draws the list's border lines and item borders. The derived combo boxes call it and then draw the item's text, or image and text, on top.

RefreshPaint

protected virtual void RefreshPaint(Graphics g, Rectangle bounds, int Index, bool isSelected, bool toEdit)

Redraws the selected item on the closed control, without waiting for a full repaint.

Parameters
g
The surface to draw on.
bounds
The closed control's face, in device pixels.
Index
The index of the selected item, or -1 when there is none.
isSelected
true to draw the item highlighted.
toEdit
true when the face is being drawn for the closed control.
Remarks

The base fills the face, leaving the push-style drop-down button clear, and redraws the drop-down button of the closed control; the derived combo boxes draw the item over it.

SetData

protected virtual void SetData()

Draws the control in its disabled state: a plain face, a dark grey border and a dimmed drop-down button, with the selected item's text in the dimmed system colour.

Remarks

Called while the control is disabled, when it paints. The base draws the frame and the button; the derived combo boxes override it to draw their item – text, or image and text – over it. Call the base implementation from an override.

WndProc

protected override void WndProc(ref Message m)

Processes Windows messages, redrawing the flat border and drop-down button after the control has painted itself.

Parameters
m
The message to process.

Fields

DropDownButtonWidth

protected const int DropDownButtonWidth

The width, in logical pixels, of the area the flat drop-down button's arrow is drawn in; it is 12.

Remarks

A derived control drawing its own drop-down button can use it to line its arrow up with the built-in one. It is scaled to the display at the point of drawing. The whole button strip is wider; see DropDownButtonExtent.