Back to Devexpress

How to: Custom Paint ComboBoxEdit's Items

windowsforms-9474-controls-and-libraries-editors-and-simple-controls-examples-how-to-custom-paint-comboboxedits-items.md

latest1.4 KB
Original Source

How to: Custom Paint ComboBoxEdit's Items

  • Oct 25, 2019

The following ComboBoxEdit.DrawItem event handler shows how you can perform custom painting of items in the dropdown list.

Selected items are drawn with the bold font. For other items, the default control’s painting is performed.

The following image shows a combo box editor whose items are drawn in this manner:

csharp
using DevExpress.XtraEditors;

private void comboBoxEdit1_DrawItem(object sender, ListBoxDrawItemEventArgs e){
    if((e.State & DrawItemState.Selected) > 0) {
        e.Appearance.FontStyleDelta = FontStyle.Bold;
        e.Cache.DrawString(e.Item.ToString(), e.Appearance.Font, e.Appearance.GetForeBrush(e.Cache),
            e.Bounds);
        e.Handled = true;
    }
}
vb
Private Sub ComboBoxEdit1_DrawItem(ByVal sender As Object, _
  ByVal e As DevExpress.XtraEditors.ListBoxDrawItemEventArgs) _
  Handles ComboBoxEdit1.DrawItem
    If (e.State And DrawItemState.Selected) > 0 Then
        e.Appearance.FontStyleDelta = FontStyle.Bold
        e.Cache.DrawString(e.Item.ToString(), e.Appearance.Font, e.Appearance.GetForeBrush(e.Cache), e.Bounds)
        e.Handled = True
    End If
End Sub