logo
VitNX3 Documentation

# VitNX_RadioButton.OnPaint Method

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

    protected override void OnPaint(
       PaintEventArgs e
    )

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

#### Parameters

e
  PaintEventArgs

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

    protected override void OnPaint(PaintEventArgs e)
     {
         var g = e.Graphics;
         var rect = new Rectangle(0, 0, ClientSize.Width, ClientSize.Height);

         var size = Constsants.RadioButtonSize;

         var textColor = Colors.LightText;
         var borderColor = Colors.LightText;
         var fillColor = Colors.LightestBackground;

         if (Enabled)
         {
             if (Focused)
             {
                 borderColor = Colors.BlueHighlight;
                 fillColor = Colors.BlueSelection;
             }

             if (_controlState == VitNX_ControlState.Hover)
             {
                 borderColor = Colors.BlueHighlight;
                 fillColor = Colors.BlueSelection;
             }
             else if (_controlState == VitNX_ControlState.Pressed)
             {
                 borderColor = Colors.GreyHighlight;
                 fillColor = Colors.GreySelection;
             }
         }
         else
         {
             textColor = Colors.DisabledText;
             borderColor = Colors.GreyHighlight;
             fillColor = Colors.GreySelection;
         }

         using (var b = new SolidBrush(Colors.GreyBackground))
         {
             g.FillRectangle(b, rect);
         }

         g.SmoothingMode = SmoothingMode.HighQuality;

         using (var p = new Pen(borderColor))
         {
             var boxRect = new Rectangle(0, (rect.Height / 2) - (size / 2), size, size);
             g.DrawEllipse(p, boxRect);
         }

         if (Checked)
         {
             using (var b = new SolidBrush(fillColor))
             {
                 Rectangle boxRect = new Rectangle(3, (rect.Height / 2) - ((size - 7) / 2) - 1, size - 6, size - 6);
                 g.FillEllipse(b, boxRect);
             }
         }

         g.SmoothingMode = SmoothingMode.Default;

         using (var b = new SolidBrush(textColor))
         {
             var stringFormat = new StringFormat
             {
                 LineAlignment = StringAlignment.Center,
                 Alignment = StringAlignment.Near
             };

             var modRect = new Rectangle(size + 4, 0, rect.Width - size, rect.Height);
             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_RadioButton Class
VitNX.UI.ControlsV1.Controls Namespace