Windows Forms radio button controls are designed to give users a choice among
two or more settings, of which only one can be assigned to a procedure or
object. For example, a group of radio button controls may display a choice of package carriers for
an order, but only one of the carriers will be used. Therefore only one radio button at a time can be selected, even if it is a part of a
functional group.
You group radio buttons by
drawing them inside a container such as a panel control, a group box control, or a form. All radio buttons that are added
directly to a form become one group. To add separate groups, you must place
them inside panels or group boxes. For more information about panels or group
boxes.
C#..Coding
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string sorce = "";
string destination = "";
foreach (Control cnt in groupBox1.Controls)
{
if (cnt is RadioButton)
{
RadioButton radio = (RadioButton)cnt;
if (radio.Checked == true)
sorce = radio.Text;
}
}
foreach (Control cnt in groupBox2.Controls)
{
if (cnt is RadioButton)
{
RadioButton radio = (RadioButton)cnt;
if (radio.Checked == true)
sorce = radio.Text;
}
}
foreach (Control cnt in groupBox3.Controls)
{
if (cnt is RadioButton)
{
RadioButton radio = (RadioButton)cnt;
if (radio.Checked == true)
sorce = radio.Text;
}
}
foreach (Control cnt in groupBox4.Controls)
{
if (cnt is RadioButton)
{
RadioButton radio = (RadioButton)cnt;
if (radio.Checked == true)
destination = radio.Text;
}
}
foreach (Control cnt in groupBox5.Controls)
{
if (cnt is RadioButton)
{
RadioButton radio = (RadioButton)cnt;
if (radio.Checked == true)
destination = radio.Text;
}
}
foreach (Control cnt in groupBox6.Controls)
{
if (cnt is RadioButton)
{
RadioButton radio = (RadioButton)cnt;
if (radio.Checked == true)
destination = radio.Text;
}
}
MessageBox.Show("you select journy" + sorce + " to " + destination);
}
}
}
Comments
Post a Comment