VitNX_ComboBox.OnDrawItem Method
Raises the DrawItem event.
protected override void OnDrawItem(DrawItemEventArgs e)
{
var g = e.Graphics;
var rect = e.Bounds;
var textColor = Colors.LightText;
var fillColor = Colors.LightBackground;
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected || (e.State & DrawItemState.Focus) == DrawItemState.Focus || (e.State & DrawItemState.NoFocusRect) != DrawItemState.NoFocusRect) { fillColor = Colors.BlueSelection; }
using (var b = new SolidBrush(fillColor)) { g.FillRectangle(b, rect); }
if (e.Index >= 0 && e.Index < Items.Count)
{
var text = Items[e.Index].ToString();
using (var b = new SolidBrush(textColor))
{
var padding = 2;
var modRect = new Rectangle(rect.Left + padding, rect.Top + padding, rect.Width - (padding * 2), rect.Height - (padding * 2));
var stringFormat = new StringFormat
{
LineAlignment = StringAlignment.Center,
Alignment = StringAlignment.Near,
FormatFlags = StringFormatFlags.NoWrap,
Trimming = StringTrimming.EllipsisCharacter
};
g.DrawString(text, Font, b, modRect, stringFormat);
}
}
}
This language is not supported or no code example is available.
.NET Framework
Supported in: 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Core
Supported in: 5.0+, 6.0+