VitNX_DropdownList.OnPaint Method

Raises the Paint event.
protected override void OnPaint( 
PaintEventArgs e 
)
This language is not supported or no code example is available.

Parameters

e
PaintEventArgs

A PaintEventArgs that contains the event data.

protected override void OnPaint(PaintEventArgs e)
 {
     var g = e.Graphics;
 
     // Draw background
     using (var b = new SolidBrush(Colors.MediumBackground))
     {
         g.FillRectangle(b, ClientRectangle);
     }
 
     // Draw normal state
     if (ControlState == VitNX_ControlState.Normal)
     {
         if (ShowBorder)
         {
             using (var p = new Pen(Colors.LightBorder, 1))
             {
                 var modRect = new Rectangle(ClientRectangle.Left, ClientRectangle.Top, ClientRectangle.Width - 1, ClientRectangle.Height - 1);
                 g.DrawRectangle(p, modRect);
             }
         }
     }
 
     // Draw hover state
     if (ControlState == VitNX_ControlState.Hover)
     {
         using (var b = new SolidBrush(Colors.VitNXBorder))
         {
             g.FillRectangle(b, ClientRectangle);
         }
 
         using (var b = new SolidBrush(Colors.VitNXBackground))
         {
             var arrowRect = new Rectangle(ClientRectangle.Right - DropdownIcons.small_arrow.Width - 8, ClientRectangle.Top, DropdownIcons.small_arrow.Width + 8, ClientRectangle.Height);
             g.FillRectangle(b, arrowRect);
         }
 
         using (var p = new Pen(Colors.BlueSelection, 1))
         {
             var modRect = new Rectangle(ClientRectangle.Left, ClientRectangle.Top, ClientRectangle.Width - 1 - DropdownIcons.small_arrow.Width - 8, ClientRectangle.Height - 1);
             g.DrawRectangle(p, modRect);
         }
     }
 
     // Draw pressed state
     if (ControlState == VitNX_ControlState.Pressed)
     {
         using (var b = new SolidBrush(Colors.VitNXBorder))
         {
             g.FillRectangle(b, ClientRectangle);
         }
 
         using (var b = new SolidBrush(Colors.BlueSelection))
         {
             var arrowRect = new Rectangle(ClientRectangle.Right - DropdownIcons.small_arrow.Width - 8, ClientRectangle.Top, DropdownIcons.small_arrow.Width + 8, ClientRectangle.Height);
             g.FillRectangle(b, arrowRect);
         }
     }
 
     // Draw dropdown arrow
     using (var img = DropdownIcons.small_arrow)
     {
         g.DrawImageUnscaled(img, ClientRectangle.Right - img.Width - 4, ClientRectangle.Top + (ClientRectangle.Height / 2) - (img.Height / 2));
     }
 
     // Draw selected item
     if (SelectedItem != null)
     {
         // Draw Icon
         var hasIcon = SelectedItem.Icon != null;
 
         if (hasIcon)
         {
             g.DrawImageUnscaled(SelectedItem.Icon, new Point(ClientRectangle.Left + 5, ClientRectangle.Top + (ClientRectangle.Height / 2) - (_iconSize / 2)));
         }
 
         // Draw Text
         using (var b = new SolidBrush(Colors.LightText))
         {
             var stringFormat = new StringFormat
             {
                 Alignment = StringAlignment.Near,
                 LineAlignment = StringAlignment.Center
             };
 
             var rect = new Rectangle(ClientRectangle.Left + 2, ClientRectangle.Top, ClientRectangle.Width - 16, ClientRectangle.Height);
 
             if (hasIcon)
             {
                 rect.X += _iconSize + 7;
                 rect.Width -= _iconSize + 7;
             }
 
             g.DrawString(SelectedItem.Text, Font, b, rect, 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+

In this article

Definition