private void LB_DrawItem(object sender, DrawItemEventArgs e)
{
bool selected = (e.State & DrawItemState.Selected) == DrawItemState.Selected;
if (e.Index == -1)
return;
object li = FontListbox.Items[e.Index];
string text = li.ToString();
Brush fg = selected ? SystemBrushes.HighlightText : SystemBrushes.WindowText;
if (selected)
{
const int ofs = 37;
e.Graphics.FillRectangle(SystemBrushes.Window,
new Rectangle(ofs, e.Bounds.Top, e.Bounds.Width - ofs, FontListbox.ItemHeight));
e.Graphics.FillRectangle(SystemBrushes.Highlight,
new Rectangle(ofs + 1, e.Bounds.Top + 1, e.Bounds.Width - ofs - 2,
FontListbox.ItemHeight - 2));
ControlPaint.DrawFocusRectangle(e.Graphics,
new Rectangle(ofs, e.Bounds.Top, e.Bounds.Width - ofs,
FontListbox.ItemHeight));
}
else
{
e.Graphics.FillRectangle(SystemBrushes.Window, 0, e.Bounds.Top, e.Bounds.Width, FontListbox.ItemHeight);
}
e.Graphics.DrawString(text, e.Font, fg, 38, e.Bounds.Top + 4);
e.Graphics.SetClip(new Rectangle(1, e.Bounds.Top + 2, 34, FontListbox.ItemHeight - 4));
e.Graphics.FillRectangle(SystemBrushes.Highlight,
new Rectangle(1, e.Bounds.Top + 2, 34, FontListbox.ItemHeight - 4));
IntPtr hdc = e.Graphics.GetHdc();
var gf = new GDIFont(text, 9);
int a = 0;
IntPtr res = NativeMethods.SelectObject(hdc, gf.hFont);
NativeMethods.SetTextColor(hdc, ColorTranslator.ToWin32(SystemColors.Window));
NativeMethods.SetBkMode(hdc, 0);
NativeMethods.TabbedTextOut(hdc, 3, e.Bounds.Top + 5, "abc", 3, 0, ref a, 0);
NativeMethods.SelectObject(hdc, res);
gf.Dispose();
e.Graphics.ReleaseHdc(hdc);
e.Graphics.DrawRectangle(Pens.Black, new Rectangle(1, e.Bounds.Top + 2, 34, FontListbox.ItemHeight - 4));
e.Graphics.ResetClip();
}