Unit 'ComboEx' Package
[Overview][Types][Classes][Procedures and functions][Index] [#lcl]

TCustomComboBoxEx.DrawItem

Draws an item in the control.

Declaration

Source position: comboex.pas line 156

protected procedure TCustomComboBoxEx.DrawItem(

  Index: Integer;

  ARect: TRect;

  State: TOwnerDrawState

); override;

Arguments

Index

  

Ordinal position for the item drawn in the method.

ARect

  

Display rectangle for the item drawn in the method.

State

  

State used to draw the item in the control.

Description

DrawItem is an overridden procedure used to draw an item in the extended combo-box control.

Index contains the ordinal position for the TComboExItem instance in ItemsEx that is drawn in the method.

ARect is the rectangle with the coordinates for the item. The values in ARect are set in the calling procedure (LMDrawListItem in TCustomComboBox). When the left coordinate is greater than zero (0), the item is a sub-item (or not a main item). Sub-items are drawn with the additional spacing in Indent applied to the drawing rectangle.

State contains the owner draw state used to render the item, and determines the window, border, and font colors for the control.

DrawItem uses ThemeServices to get theme details applied to enabled items in the combo-box. DrawItem ensures that a valid text height is available for the control Canvas, and is used to draw the text for the item.

When Images have been assigned for the control, the image index appropriate for the value in State is determined. The value odSelected causes the SelectedImageIndex for the item is be used. Otherwise, the ImageIndex for the item is used.

The image size is determined by calling the SizeForPPI method in Images using the ImagesWidth and the display density for the current Font. DrawItem determines the location for the image and the indent spacing for the current BiDiMode setting for the control. Right-to-Left rendering aligns the image and indent to the right-hand edge of the drawing rectangle. The DrawIcon method in ThemeServices is called to render the icon to the control Canvas using the theme details.

Images are not drawn when Images is unassigned or contains zero (0) images, or when values have not been explicitly assigned to either ImageIndex or SelectedImageIndex for the extended item in Index.

DrawItem configures the Canvas to use the brush style and font color needed for the value in State. Text drawing flags are derived for the item, and the text is rendered by calling the DrawText method.

Remark: DrawItem does NOT call the inherited method in TCustomComboBox or trigger its OnDrawItem event handler. The item is rendered entirely in this method.