logo
VitNX3 Documentation

# VitNX_ComboBox.OnDrawItem Method

Namespace: VitNX.UI.ControlsV1.Controls
Assembly: VitNX3 (in VitNX3.dll)
Raises the DrawItem event.
VB
C#
F#
C++
JScript
Copy

    protected override void OnDrawItem(
       DrawItemEventArgs e
    )

    This language is not supported or no code example is available.

#### Parameters

e
  DrawItemEventArgs

A DrawItemEventArgs that contains the event data.

Source code
VB
C#
F#
C++
JScript
Copy

    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.

Applies to

#### .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+
See Also
VitNX_ComboBox Class
VitNX.UI.ControlsV1.Controls Namespace