void m_Combo_DrawItem(object sender, DrawItemEventArgs e)
{
int iconWidth = SystemInformation.SmallIconSize.Width;
int indent = ((e.State & DrawItemState.ComboBoxEdit) == 0) ? (iconWidth / 2) : 0;
if (e.Index != -1)
{
string display;
ComboItem item = (ComboItem)m_Combo.Items[e.Index];
Color textColor = SystemColors.WindowText;
Rectangle textRect;
int textOffset;
SizeF size;
if ((e.State & DrawItemState.ComboBoxEdit) != 0)
{
// Don't draw the folder location in the edit box when
// the control is Editable as the edit control will
// take care of that.
display = m_Editable ? string.Empty : GetEditString();
}
else
{
display = item.Folder.DisplayName;
}
size = TextRenderer.MeasureText(display, m_Combo.Font);
textRect = new Rectangle(e.Bounds.Left + iconWidth + (item.Indent * indent) + 3, e.Bounds.Y, (int)size.Width, e.Bounds.Height);
textOffset = (int)((e.Bounds.Height - size.Height) / 2);
// If the text is being drawin in the main combo box edit area,
// draw the text 1 pixel higher - this is how it looks in Windows.
if ((e.State & DrawItemState.ComboBoxEdit) != 0)
{
textOffset -= 1;
}
if ((e.State & DrawItemState.Selected) != 0)
{
e.Graphics.FillRectangle(SystemBrushes.Highlight, textRect);
textColor = SystemColors.HighlightText;
}
else
{
e.DrawBackground();
}
if ((e.State & DrawItemState.Focus) != 0)
{
ControlPaint.DrawFocusRectangle(e.Graphics, textRect);
}
SystemImageList.DrawSmallImage(
e.Graphics,
new Point(e.Bounds.Left + (item.Indent * indent), e.Bounds.Top),
item.Folder.GetSystemImageListIndex(ShellIconType.SmallIcon,
ShellIconFlags.OverlayIndex),
(e.State & DrawItemState.Selected) != 0
);
TextRenderer.DrawText(e.Graphics, display, m_Combo.Font, new Point(textRect.Left, textRect.Top + textOffset), textColor);
}
}