HypernovaDesktop Components · docs
Binarymission
WinForms › Button Suite › ExtendedRadioButton

ExtendedRadioButton

class.NET 6 / 8 / 10.NET Framework 4.8Binarymission.WinForms.Controls.ButtonControls

A radio button that draws its own circle, dot and text, in colours you choose – a crisp, flat radio button that looks the same on every version of Windows and at every display scale.

public sealed class ExtendedRadioButton : System.Windows.Forms.RadioButton

Inherits from / implements: System.Windows.Forms.RadioButton

Remarks

It is a RadioButton in every other way: Checked, the grouping of the buttons in the same container, CheckedChanged, the arrow keys and the accessibility all work as usual. Only the picture changes.

Colours

A disabled button is drawn with a grey circle and dot and grey text.

Size and layout

The circle grows with the font (to about four fifths of the font's height, and never below 11 logical pixels) and is drawn smoothed at every display scale. CheckAlign, TextAlign, Control.Padding and Control.RightToLeft place the circle and the text as on a standard radio button.

Examples

A choice of delivery speed, grouped in a GroupBox so only one can be chosen.

using System;
using System.Drawing;
using System.Windows.Forms;
using Binarymission.WinForms.Controls.ButtonControls;

// In the checkout form's constructor:
GroupBox delivery = new GroupBox { Text = "Delivery", Location = new Point(16, 16), Size = new Size(240, 110) };

string[] options = { "Standard (3-5 days)", "Express (next day)", "Collect from store" };
for (int i = 0; i < options.Length; i++)
{
    ExtendedRadioButton option = new ExtendedRadioButton
    {
        Text = options[i],
        Location = new Point(12, 24 + i * 26),
        AutoSize = true,
        Checked = i == 0,
        NormalBorderColor = Color.DarkSlateGray,
        OnFocusControlColor = Color.DarkOrange
    };
    option.CheckedChanged += (sender, e) =>
    {
        ExtendedRadioButton chosen = (ExtendedRadioButton)sender;
        if (chosen.Checked)
        {
            Console.WriteLine("Delivery: " + chosen.Text);
        }
    };
    delivery.Controls.Add(option);
}

Controls.Add(delivery);

See also

Members at a glance

Constructors
ExtendedRadioButtonInitialises a new, unselected radio button with a black circle and dot that turn to the system highlight colour under the pointer.
Properties
ControlBackColorGets or sets the colour that fills the inside of the circle.
FlatStyleGets or sets the flat style of the control, which is always Flat.
NormalBorderColorGets or sets the colour of the circle and the dot while the pointer is away and the button does not have the focus.
OnFocusControlColorGets or sets the colour of the circle and the dot while the pointer is over the button or it has the keyboard focus.
Methods
GetPreferredSizeCalculates the size that fits the circle, the gap beside it and the text on one line.
OnGotFocusRaises the Control.GotFocus event and redraws the circle in OnFocusControlColor.
OnLostFocusRaises the Control.LostFocus event and redraws the circle in its normal colour.
OnMouseEnterRaises the Control.MouseEnter event and redraws the circle in OnFocusControlColor.
OnMouseLeaveRaises the Control.MouseLeave event and redraws the circle in its normal colour.
OnPaintDraws the control: the background, the circle and its dot, the text, and the focus rectangle.
WndProcProcesses Windows messages exactly as the base control does.

Constructors

ExtendedRadioButton

public ExtendedRadioButton()

Initialises a new, unselected radio button with a black circle and dot that turn to the system highlight colour under the pointer.

Properties

ControlBackColor

public Color ControlBackColor

Gets or sets the colour that fills the inside of the circle.

Value
The fill colour of the circle. The default is SystemColors.Window.
Remarks

It fills the circle only, in every state, disabled included; the area round the circle and the text is the control's Control.BackColor.

See also

FlatStyle

public new FlatStyle FlatStyle

Gets or sets the flat style of the control, which is always Flat.

Value
Always Flat; a value set is ignored.
Remarks

Hidden from the designer and IntelliSense: the control draws every part of itself, so the base control's styles do not apply.

NormalBorderColor

public Color NormalBorderColor

Gets or sets the colour of the circle and the dot while the pointer is away and the button does not have the focus.

Value
The circle and dot colour at rest. The default is Color.Black.
Remarks

While the pointer is over the button or it has the focus, OnFocusControlColor is used instead; a disabled button uses the system's dark grey. The check box's equivalent is ExtendedCheckBox.NormalControlColor.

See also

OnFocusControlColor

public Color OnFocusControlColor

Gets or sets the colour of the circle and the dot while the pointer is over the button or it has the keyboard focus.

Value
The highlighted circle and dot colour. The default is SystemColors.Highlight.
Remarks

The button returns to NormalBorderColor when the pointer leaves it or it loses the focus, whichever happens first.

See also

Methods

GetPreferredSize

public override Size GetPreferredSize(Size proposedSize)

Calculates the size that fits the circle, the gap beside it and the text on one line.

Parameters
proposedSize
The size the layout is offering. Not used: the result depends only on the text, font and Control.Padding.
Returns

The width and height, in pixels, that show the whole text without wrapping.

Remarks

This is what Control.AutoSize uses, so an auto-sized control grows with its font and its circle, which is sized from the font.

OnGotFocus

protected override void OnGotFocus(EventArgs e)

Raises the Control.GotFocus event and redraws the circle in OnFocusControlColor.

Parameters
e
The event data.

OnLostFocus

protected override void OnLostFocus(EventArgs e)

Raises the Control.LostFocus event and redraws the circle in its normal colour.

Parameters
e
The event data.

OnMouseEnter

protected override void OnMouseEnter(EventArgs e)

Raises the Control.MouseEnter event and redraws the circle in OnFocusControlColor.

Parameters
e
The event data.

OnMouseLeave

protected override void OnMouseLeave(EventArgs e)

Raises the Control.MouseLeave event and redraws the circle in its normal colour.

Parameters
e
The event data.

OnPaint

protected override void OnPaint(PaintEventArgs e)

Draws the control: the background, the circle and its dot, the text, and the focus rectangle.

Parameters
e
The graphics surface and clip rectangle to paint.
Remarks

While Appearance is Normal the control draws itself completely and the Control.Paint event is not raised. With Button, the base control draws the push-button look, raises Control.Paint as usual, and this control's colours do not apply.

The background is the control's Control.BackColor; a fully transparent one takes the colour of the nearest parent that has an opaque background.

WndProc

protected override void WndProc(ref Message m)

Processes Windows messages exactly as the base control does.

Parameters
m
The message to process.