This example demonstrates how to create and use radio buttons and radio button groups.
A radio button (NRadioButton) is a kind of a toggle button, which is intended to be placed inside the sub-hierarchy of a radio button group (NRadioButtonGroup). When there are multiple radio buttons inside the radio button group sub-hierarchy, only one can be checked at a time. Checking a different radio button will automatically uncheck the previously checked one.
The radio button group (NRadioButtonGroup) is a content container, thus it is up to the developer to choose the style in which the radio buttons are arranged. In this example we have created two radio groups, each of which holding a stack panel (horizontal or vertical) that contain radio buttons. It is however possible to arrange the radio buttons in any way that you see fit.

| Language: C# |
using Nevron.Nov;
using Nevron.Nov.Dom;
using Nevron.Nov.Editors;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System;
using System.Windows.Forms;
namespace NovWinFormsProject
{
public partial class Form1 : Form
{
#region Constructors
public Form1()
{
InitializeComponent();
// Set form title
Text = "NOV WinForms - NRadioButtonExample";
// Create the NOV example and its controls
NWidget exampleContent = CreateExampleContent();
NWidget exampleControls = CreateExampleControls();
if (exampleControls != null)
{
exampleControls.PreferredWidth = 300;
}
// Place the example and its controls in a pair box
NPairBox pairBox = new NPairBox(exampleContent, exampleControls);
pairBox.FillMode = ENStackFillMode.First;
pairBox.FitMode = ENStackFitMode.First;
pairBox.Margins = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing);
// Host the example in the form
NNovWidgetHost host = new NNovWidgetHost(pairBox);
host.Dock = DockStyle.Fill;
Controls.Add(host);
}
#endregion
#region Example
public NWidget CreateExampleContent()
{
NTab tab = new NTab();
// create a tab page with vertically arranged radio buttons
NTabPage verticalTabPage = new NTabPage("Vertical Radio Group");
tab.TabPages.Add(verticalTabPage);
NRadioButtonGroup verticalRadioGroup = new NRadioButtonGroup();
verticalRadioGroup.HorizontalPlacement = ENHorizontalPlacement.Left;
verticalRadioGroup.VerticalPlacement = ENVerticalPlacement.Top;
verticalTabPage.Content = verticalRadioGroup;
NStackPanel verticalStack = new NStackPanel();
verticalRadioGroup.Content = verticalStack;
for (int i = 0; i < 5; i++)
{
NRadioButton radioButton = new NRadioButton("Item " + i.ToString());
verticalStack.Add(radioButton);
}
NRadioButton disabledRadioButton1 = new NRadioButton("Disabled");
disabledRadioButton1.Enabled = false;
verticalStack.Add(disabledRadioButton1);
verticalRadioGroup.SelectedIndexChanged += OnVerticalRadioGroupSelectedIndexChanged;
// create a tab page with horizontally arranged radio buttons
NTabPage horizontalTabPage = new NTabPage("Horizontal Radio Group");
tab.TabPages.Add(horizontalTabPage);
NRadioButtonGroup horizontalRadioGroup = new NRadioButtonGroup();
horizontalRadioGroup.VerticalPlacement = ENVerticalPlacement.Top;
horizontalRadioGroup.HorizontalPlacement = ENHorizontalPlacement.Left;
horizontalTabPage.Content = horizontalRadioGroup;
NStackPanel horizontalStack = new NStackPanel();
horizontalStack.Direction = ENHVDirection.LeftToRight;
horizontalRadioGroup.Content = horizontalStack;
for (int i = 0; i < 5; i++)
{
NRadioButton radioButton = new NRadioButton("Item " + i.ToString());
horizontalStack.Add(radioButton);
}
NRadioButton disabledRadioButton2 = new NRadioButton("Disabled");
disabledRadioButton2.Enabled = false;
horizontalStack.Add(disabledRadioButton2);
horizontalRadioGroup.SelectedIndexChanged += OnHorizontalRadioGroupSelectedIndexChanged;
return tab;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
stack.FillMode = ENStackFillMode.Last;
stack.FitMode = ENStackFitMode.Last;
// create the events list box
m_EventsLog = new NExampleEventsLog();
stack.Add(m_EventsLog);
return stack;
}
public string GetExampleDescription()
{
return @"
This example demonstrates how to create and use radio buttons and radio button groups.
A radio button (NRadioButton) is a kind of a toggle button, which is intended to be placed inside the sub-hierarchy of a radio button group (NRadioButtonGroup).
When there are multiple radio buttons inside the radio button group sub-hierarchy, only one can be checked at a time.
Checking a different radio button will automatically uncheck the previously checked one.
The radio button group (NRadioButtonGroup) is a content container, thus it is up to the developer to choose the style in which the radio buttons are arranged.
In this example we have created two radio groups, each of which holding a stack panel (horizontal or vertical) that contain radio buttons.
It is however possible to arrange the radio buttons in any way that you see fit.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Toggle Buttons", "https://www.nevron.com/docs/openvision/ui-toggle-buttons.html"),
("Buttons Overview", "https://www.nevron.com/docs/openvision/ui-buttons-overview.html"),
};
}
#endregion
#region Implementation
#endregion
#region Event Handlers
private void OnHorizontalRadioGroupSelectedIndexChanged(NValueChangeEventArgs args)
{
m_EventsLog.LogEvent("Horizontal Radio Selected: " + (int)args.NewValue);
}
private void OnVerticalRadioGroupSelectedIndexChanged(NValueChangeEventArgs args)
{
m_EventsLog.LogEvent("Vertical Radio Selected: " + (int)args.NewValue);
}
#endregion
#region Fields
NExampleEventsLog m_EventsLog;
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
}