BinaryComboBox
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
Simpleis not supported:DropDownStyleignores it.- Right-to-left layout is not supported:
RightToLeftstaysNo. - The flat drawing is used by
BinaryImageComboBoxalways, and byBinaryTextComboBoxwhile itsBinaryTextComboBox.DisplayStyleIsFlatistrue; otherwise the text combo box looks like a standard Windows combo box and the colours here are not used. - Metrics are logical pixels (1/96 inch), scaled to the display the control is on.
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 | |
|---|---|
BinaryComboBox | Sets up the owner-drawn, flat painting and the default colours shared by the Hypernova combo boxes. |
| Properties | |
AlphaBlendFactorForControlPainting | Gets or sets the blend weight used for the background of the flat drop-down button's arrow area. |
AlphaBlendFactorForDropDownPressedColor | Gets or sets how strongly CustomPaintingColor shows in the drop-down button while the list is open. |
AlphaBlendFactorForItemSelectionColor | Gets or sets how strongly CustomPaintingColor shows in the highlighted item and the drop-down button face. |
ControlArrowColor | Gets or sets the colour of the arrow (chevron) on the drop-down button. |
CustomControlBorderColor | Gets or sets the colour of the control's border and of the outline round its drop-down button. |
CustomControlBorderColorWhenNotInFocus | Gets or sets the colour of the border, and of the drop-down button, while the control does not have the focus. |
CustomControlDropDownButtonFillColorWhenNotInFocus | Gets or sets the colour that fills the drop-down button while the control does not have the focus. |
CustomPaintingColor | Gets or sets the accent colour the control blends to fill its drop-down button and the highlighted item. |
DropDownItemBorderColor | Gets or sets the colour of the rectangle drawn round each item in the single-column drop-down list. |
DropDownItemTextAlignment | Gets or sets how the item text is aligned in the drop-down list. |
DropDownStyle | Gets or sets whether the user can type into the control (DropDown) or can only
pick from the list (DropDownList). |
DropDownWindowBackgroundColor | Gets or sets the background colour of the single-column drop-down list. |
DropDownWindowBorderColor | Gets or sets the colour of the border drawn round the single-column drop-down list. |
DropDownWindowBorderThickness | Gets or sets the width of the border drawn round the single-column drop-down list. |
ExtendedDropdownButtonImage | Gets or sets a picture that replaces the whole push-button style drop-down button. |
ExtendedDropdownButtonInternalImage | Gets or sets the small arrow image drawn on the push-button style drop-down button, in place of the built-in arrow. |
IsInExtendedReadOnlyMode | Gets or sets whether a read-only text combo box also refuses changes to its selection, not just to its text. |
MultiColumnDropDownWindowBorderThickness | Gets or sets the width of the frame round the multi-column drop-down when it shows a header and footer. |
MultiColumnWindowColumnsHorizontalAlignments | Gets or sets the alignment of each column in the multi-column drop-down, in column order. |
ReflectCurrentXPThemeColorOnLoad | Gets or sets whether the control takes its colours from the current Windows colour scheme when its window is created. |
RightToLeft | Gets the control's right-to-left setting, which is always No:
right-to-left layout is not supported. |
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. |
ShouldDisplayColumnHeadersWhenInMultiColumnMode | Gets or sets whether the multi-column drop-down shows its row of column headings. |
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. |
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. |
TextAlignment | Gets or sets how the selected item's text is aligned on the closed control. |
UpdateWhenSystemColorsChanges | Gets or sets whether the control applies the current Windows colour scheme again whenever the system colours change. |
| Methods | |
DropDownButtonExtent | Returns the width of the drop-down button strip at the right of the control, in device pixels. |
EmulateThisXPTheme | Colours the control to match one of the Windows XP colour schemes: Blue, Olive Green or Silver. |
MakeBlank | Clears the selection, so the control shows no item. |
MeasureTextViaGdi | Measures text the way GDI draws it, for laying out text that the control draws. |
OnDrawItem | Draws one item of the list, or the selected item on the closed control, by calling
PaintControlWithData. |
OnGotFocus | Raises the Control.GotFocus event and redraws the border and drop-down button in their highlighted colours. |
OnHandleCreated | 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. |
OnKeyPress | Raises the Control.KeyPress event; an exception thrown by a handler is absorbed rather than
propagated, so a faulty handler cannot close the form. |
OnLostFocus | Raises the Control.LostFocus event and redraws the border and drop-down button in their resting state. |
OnMouseEnter | Raises the Control.MouseEnter event and shows the border and drop-down button in their
highlighted colours. |
OnMouseLeave | 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. |
OnPaint | Paints the closed control when it draws itself – the face, the selected item and the border – in the colours set on the control. |
OnSelectedIndexChanged | Raises the ComboBox.SelectedIndexChanged event; an exception thrown by a handler is absorbed
rather than propagated. |
OnSystemColorsChanged | Raises the Control.SystemColorsChanged event and, when UpdateWhenSystemColorsChanges
is set, applies the colour scheme of the current Windows theme again. |
PaintControlWithData | Draws one item, either in the drop-down list or as the selected item on the closed control. |
RefreshPaint | Redraws the selected item on the closed control, without waiting for a full repaint. |
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. |
WndProc | Processes Windows messages, redrawing the flat border and drop-down button after the control has painted itself. |
| Fields | |
DropDownButtonWidth | The width, in logical pixels, of the area the flat drop-down button's arrow is drawn in; it is 12. |
Constructors
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
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
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
CustomPaintingColoritself, 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
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
CustomPaintingColoritself, 0 isSystemColors.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
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
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
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.Transparentto useCustomControlBorderColorall the time. The default isColor.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
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.Transparentto fill the button withCustomControlBorderColorWhenNotInFocus. The default isColor.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
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
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
Gets or sets how the item text is aligned in the drop-down list.
- Value
- One of the
HorizontalAlignmentvalues. The default isHorizontalAlignment.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
Gets or sets whether the user can type into the control (DropDown) or can only
pick from the list (DropDownList).
- Value
- One of the
ComboBoxStylevalues other thanSimple. The default depends on the derived control:DropDownforBinaryTextComboBox,DropDownListforBinaryImageComboBox.
Remarks
Simple is not supported: setting it is ignored and the style stays as it was.
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
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
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
Gets or sets a picture that replaces the whole push-button style drop-down button.
- Value
- The button picture, or
nullto draw the themed push button. The default isnull.
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
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
nullfor the built-in arrow. The default isnull.
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
Gets or sets whether a read-only text combo box also refuses changes to its selection, not just to its text.
- Value
trueto lock the selection as well as the text. The default isfalse.
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
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
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.
BinaryTextComboBoxstarts with an empty list; the base class leaves itnull.
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
Gets or sets whether the control takes its colours from the current Windows colour scheme when its window is created.
- Value
trueto apply the matching scheme when the window is created. The default isfalse.- 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
Gets the control's right-to-left setting, which is always No:
right-to-left layout is not supported.
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
trueto align the suggestion list's columns the same way. The default isfalse.
Remarks
The suggestion list is the one BinaryTextComboBox.AutoCompleteStyleForMultiColumnModeIsMultiColumn turns on.
ShouldDisplayColumnHeadersWhenInMultiColumnMode
Gets or sets whether the multi-column drop-down shows its row of column headings.
- Value
trueto show the headings. The default istrue.
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
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
truefor the push-button style. The default isfalse.
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
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
trueto draw the border all the time. The default istrue.
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
Gets or sets how the selected item's text is aligned on the closed control.
- Value
- One of the
HorizontalAlignmentvalues. The default isHorizontalAlignment.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
Gets or sets whether the control applies the current Windows colour scheme again whenever the system colours change.
- Value
trueto follow changes to the system colours. The default isfalse.- 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
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
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
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
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
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
Raises the Control.GotFocus event and redraws the border and drop-down button in their highlighted colours.
Parameters
e- The event data.
OnHandleCreated
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
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
Raises the Control.LostFocus event and redraws the border and drop-down button in their resting state.
Parameters
e- The event data.
OnMouseEnter
Raises the Control.MouseEnter event and shows the border and drop-down button in their
highlighted colours.
Parameters
e- The event data.
OnMouseLeave
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
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
OnSelectedIndexChanged
Raises the ComboBox.SelectedIndexChanged event; an exception thrown by a handler is absorbed
rather than propagated.
Parameters
e- The event data.
OnSystemColorsChanged
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
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.
isSelectedtruewhen the item is the highlighted one.toEdittruewhen 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
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.
isSelectedtrueto draw the item highlighted.toEdittruewhen 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
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
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
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.