protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; if (Parent != null) { g.FillRectangle(new SolidBrush(Parent.BackColor), ClientRectangle); } g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle backgroundRect = new Rectangle( ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1); if (FillBackground) { if (!_isSelected) { if (RadioButtonFlatStyle) { LinearGradientBrush gradient = new LinearGradientBrush(backgroundRect, BackColor.Lighten(5), BackColor.Darken(25), LinearGradientMode.Vertical); g.FillPath(gradient, ExtendedForms.RoundedRect(backgroundRect, BorderRadius)); } else { g.FillPath(new SolidBrush(BackColor), ExtendedForms.RoundedRect(backgroundRect, BorderRadius)); } if (_useDarckenColorForBorder) { g.DrawPath(new Pen(BackColor.Darken(80), 1), ExtendedForms.RoundedRect(backgroundRect, BorderRadius)); } else { g.DrawPath(new Pen(BorderColor, 1), ExtendedForms.RoundedRect(backgroundRect, BorderRadius)); } } else { if (RadioButtonFlatStyle) { LinearGradientBrush gradient = new LinearGradientBrush(backgroundRect, BackColor.Lighten(30), BackColor.Lighten(15), LinearGradientMode.Vertical); g.FillPath(gradient, ExtendedForms.RoundedRect(backgroundRect, BorderRadius)); } else { g.FillPath(new SolidBrush(BackColor.Lighten(30)), ExtendedForms.RoundedRect(backgroundRect, BorderRadius)); } if (_useDarckenColorForBorder) { g.DrawPath(new Pen(BorderColor.Lighten(20), 1), ExtendedForms.RoundedRect(backgroundRect, BorderRadius)); } else { g.DrawPath(new Pen(BorderColor, 1), ExtendedForms.RoundedRect(backgroundRect, BorderRadius)); } } } int dotDiameter = ThumbRadius; int thumbY = ClientRectangle.Height / 2 - dotDiameter / 2 - 1; RectangleF innerRect = new RectangleF(Padding.Left + Spacing, thumbY, dotDiameter, dotDiameter); int textX = ( int )innerRect.Left + ( int )innerRect.Width + Spacing; SolidBrush thumbBackBrush = null; Pen thumbBorderPen = new Pen(ThumbColor, 2); SolidBrush thumbDotBrush = new SolidBrush(ThumbColor); if (_isSelected) { thumbBackBrush = _whiteBrush; thumbBorderPen = (RadioButtonFlatStyle) ? thumbBorderPen = new Pen(BackColor.Darken(120), 2) : thumbBorderPen = new Pen(ThumbColor, 2); } else { thumbBackBrush = _whiteBrush; thumbBorderPen = (RadioButtonFlatStyle) ? thumbBorderPen = new Pen(BackColor.Darken(130), 2) : thumbBorderPen = new Pen(ThumbColor, 2); } int count = (Checked || _isSelected) ? 2 : 1; for (int i = 0; i < count; i++) { if (RoundedThumb) { g.FillEllipse(((Checked || _isSelected) && i > 0) ? thumbDotBrush : thumbBackBrush, innerRect); g.DrawEllipse(thumbBorderPen, innerRect); } else { g.FillRectangle(thumbBackBrush, innerRect); g.DrawRectangle(thumbBorderPen, innerRect.X, innerRect.Y, innerRect.Width, innerRect.Height); } innerRect.Inflate(-4, -4); } StringFormat sf = new StringFormat(); sf.LineAlignment = StringAlignment.Center; sf.Alignment = StringAlignment.Near; sf.FormatFlags = StringFormatFlags.NoWrap; innerRect = new RectangleF(textX, 1, ClientRectangle.Width - 1 - dotDiameter - 2, ClientRectangle.Height - 3); SolidBrush textBrush = (ForeColor == Color.Black) ? _blackBrush : new SolidBrush(ForeColor); g.DrawString(Text, Font, textBrush, innerRect, sf); }