VitNX_GroupBox.OnPaint Method

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;
     var rect = new Rectangle(0, 0, ClientSize.Width, ClientSize.Height);
     var stringSize = g.MeasureString(Text, Font);
     var textColor = Colors.LightText;
     var fillColor = Colors.GreyBackground;
     using (var b = new SolidBrush(fillColor)) { g.FillRectangle(b, rect); }
     using (var p = new Pen(BorderColor, 1))
     {
         var borderRect = new Rectangle(0, (int)stringSize.Height / 2, rect.Width - 1, rect.Height - ((int)stringSize.Height / 2) - 1);
         g.DrawRectangle(p, borderRect);
     }
     var textRect = new Rectangle(rect.Left + Constsants.Padding, rect.Top, rect.Width - (Constsants.Padding * 2), (int)stringSize.Height);
     using (var b2 = new SolidBrush(fillColor))
     {
         var modRect = new Rectangle(textRect.Left, textRect.Top, Math.Min(textRect.Width, (int)stringSize.Width), textRect.Height);
         g.FillRectangle(b2, modRect);
     }
     using (var b = new SolidBrush(textColor))
     {
         var stringFormat = new StringFormat
         {
             LineAlignment = StringAlignment.Center,
             Alignment = StringAlignment.Near,
             FormatFlags = StringFormatFlags.NoWrap,
             Trimming = StringTrimming.EllipsisCharacter
         };
         g.DrawString(Text, Font, b, textRect, 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