.Net Controls: RadioButton |
|
A radio button, sometimes called an option button, is circular control that comes in a group with other controls of the same type. Each radio button is made or an small empty circle O. From the group, when the user clicks one of them, the radio button that was clicked becomes filled with a big dot, like this 8. When one of the radio buttons in the group is selected and displays its dot, the others display empty circles. To guide the user as to what the radio buttons mean, each is accompanied by a label.
|
Creating Radio Buttons |
To create a radio button, you can use the RadioButton class. Because radio buttons always come as a group, you should include them in another control that visibly shows that the radio buttons belong to the same group. The most common control used for this purpose is the group box created using the GroupBox control. |
|
Radio Button Properties |
Checked |
While radio buttons come as a group, only one of them can be selected at a given time. The item that is selected has its Checked property set to true. There are two main ways you can use this property. To select a particular radio button, set its Checked property to true. To find out if an item is selected, get the value of its Checked property. You can also programmatically check a radio button. Here is an example: private: System::Void Form1_Load(System::Object * sender, System::EventArgs * e) { this->radioButton2->Checked = true; }
|
The Check-Alignment |
By default, the round box of a radio button control is positioned to the left side of its accompanying label. In Microsoft .Net applications, you have many options. Besides the left position, the most common alignment consists of positioning the round box to the right side of its label. The position of the round box with regards to its label is controlled by the CheckAlign property. The possible values are: TopLeft, TopCenter, TopRight, MiddleRight, BottomRight, BottomCenter, and BottomLeft. You can also do this programmatically as follows: private: System::Void Form1_Load(System::Object * sender, System::EventArgs * e) { this->radioButton1->CheckAlign = ContentAlignment::MiddleRight; } |
The Appearance |
By default, radio buttons appear as rounded boxes that get filled with a big dot when the user selects one. Optionally, you can make a radio button appear as a toggle button. In that case, the buttons would appear as regular buttons. When the user clicks one, it appears down while the others are up. If the user clicks another button, the previous one becomes up while the new one would be down. To change the appearance of a radio button, assign the Button or Normal value to its Appearance property. The Appearance values are defined in the Appearance namespace. Here is an example:
|
Radio Button Events |
The most obvious, the most common, and the most regular event of a radio button just like any button is the OnClick event. This event fires when the user clicks the radio button. |
Related Examples: |
|
||
Home | Copyright © 2004-2014 FunctionX, Inc. | |
|