Which radiobutton is checked c




















Because radio buttons always come as a group, you should include them in another control that visibly shows that the radio buttons belong together. The most common control used for this purpose is the group box created using the GroupBox control.

Unlike most of other controls that can be positioned anywhere, a radio button should not be placed directly on a form. Instead, a radio button should be positioned in a container that belongs to a form. The typical container is the group box. When a radio button is added to a group box, the location of the radio button is relative to its parent.

This location is easy to specify if you are visually designing the application. If you are programmatically creating it, make sure you specify the location based on the control that will hold the radio button. Here are examples:.

To indicate what a radio button represents, it is accompanied by text, also referred to as its caption. To specify the caption of a radio button at a design time, type a string in the Text field of its Properties window. To programmatically specify the caption of a radio button, assign a string to its Text property. Practical Learning: Introducing Radio Buttons. The application we are going to create is used to calculate the amount owed on a loan using the following formula:.

If you add only one radio button to a container, when the application starts, the lone radio button would appear with an empty round circle.

If the user clicks that lone radio button, the radio button's circle becomes filled with a dot and the user cannot remove or change this aspect. If you equip a container with more than one radio button, the user can click the desired one to select it and only one of the radio buttons can be selected at a given time. The radio button that is selected is referred to as checked. To support this description, the RadioButton class is equipped with a property named Checked. At design time, to select a radio button, in the Properties window, set its Checked property to True.

At run time, to programmatically select a radio button, assign a true value to its Checked property. To find out whether a particular radio button is selected, get the value of its Checked property. We can also use Width and Height property instead of Size property. BackColor and ForeColor properties are used to set background and foreground color of a RadioButton respectively. If you click on these properties in Properties window, the Color Dialog pops up. Alternatively, you can set background and foreground colors at run-time.

The following code snippet sets BackColor and ForeColor properties. Name property represents a unique name of a RadioButton control. It is used to access the control in the code. The following code snippet sets and gets the name and text of a RadioButton control. Text property of a RadioButton represents the current text of a RadioButton control. The following code snippet sets the Text and TextAlign properties and gets the size of a RadioButton control.

Font property represents the font of text of a RadioButton control. If you click on the Font property in Properties window, you will see Font name, size, and other font options. The following code snippet sets the Font property at run-time. The simplest way of reading a RadioButton control's content is using the Text property. The following code snippet reads contents of a RadioButton in a string. The Button look does not have a round select option.

The following property makes a RadioButton look like a Button control. CheckAlign property is used to align the check mark in a RadioButton. By using CheckAlign and TextAlign properties, we can place text and check mark to any position on a RadioButton we want.

The following code snippet aligns radio button round circle and text to middle-right and creates a RadioButton that looks like Figure 4. An ellipsis character If AutoEllipsis property is true, it adds ellipsis character to a control if text in control does not fit.

You may have to set AutoSize to false to see the ellipses character. The following code snippet sets the AutoEllipsis property of a RadioButton to true.

Figure 5 shows a RadioButton when AutoEllipsis is true and contents do not fit in the given width of the control. When one option is choosed from the group of options of Radio Buttons and then the Button is clicked, the Selected option will be displayed in the Message Box.

Show rdoButton. The following Output will be obtained as give below in the Screenshot. Thanks For Reading My article. If there is any error or Problem with the Code feel free to comment it below. I will try to solve the Problem. View All.



0コメント

  • 1000 / 1000