C++ RadioButton Control.
The C++ RadioButton control allows you to choose one item within the parent control or group of items. When a user selects one option within a group of options the other options clear automatically. Typically the options are on the line of Yes/No, Male/Female, True/False etc. The RadioButton is very similiar to the CheckBox control. The main difference is with the CheckBox control, the user can select multiple choices within the same group of options.
Namespace: System::Windows::Forms
System.Windows.Forms (in system.windows.forms.dll)
Creating 2 new C++ Windows forms RadioButtons.
RadioButton^ Mradiobutton = gcnew RadioButton;
RadioButton^ Fradiobutton = gcnew RadioButton;
Assigning a text value to the C++ RadioButton controls.
Mradiobutton->Text = "Male";
Fradiobutton->Text = "Female";
Assigning a new location for the C++ Windows Forms RadioButton Controls.
Mradiobutton->Location = Point(10,10);
Fradiobutton->Location = Point(10,30);
Assigning the Check value to the RadioButton controls.
Mradiobutton->Checked = true;
Fradiobutton->Checked = false;
Adding a C++ RadioButton controls to the form.
this->Controls->AddRange(gcnew cli::array<RadioButton^>(2) {Mradiobutton, Fradiobutton});
Creating a CheckedChanged Event for the C++ RadioButton controls.
Fradiobutton->CheckedChanged += gcnew System::EventHandler(this, &Form1::Fradiobutton_CheckedChanged);
Mradiobutton->CheckedChanged += gcnew System::EventHandler(this, &Form1::Fradiobutton_CheckedChanged);
Responding to the C++ RadioButton CheckedChanged event.
Male RadioButton.
private: System::Void Mradiobutton_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
{
MessageBox::Show("Male Checked");
}
Female RadioButton.
private: System::Void Fradiobutton_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
{
MessageBox::Show("Female Checked");
}
|