RadioButton Control

RadioButton Control

It is used to select one and only one option from the available options in one group . Only one radio button in a group can be selected at a time.

While with the check box control, any number of checkboxes may be selected.

Property : –

1. Appearance : If the Appearance value is set to Normal, then the RadioButton control appears as a circular check box.

If the value is set to Button, then the RadioButton appears like a control that can be toggled to an up or down state. Either type can display text, an image, or both.

2. Checked : This property is used to check whether the RadioButton is selected or not. If this property is true, then RadioButton is selected. 

3. Text : It is the text that is displayed within the control. The Text property can contain an access key, which allows a user to “click” the control by pressing the ALT key with the access key.

4. FlatStyle: Gets or sets the flat style appearance of the control when a user moves the mouse pointer over the control and click. It can be Flat, Popup, Standard or System.

Method :-

(1)  Performclick : Generates a Click event for the control, simulating a click by a user.

This method comes in handy when the code in the click event has to be executed even when the user has not clicked the RadioButton.

Event :-

(1) CheckedChanged : It occurs when the value of the Checked property changes. It is default event of RadioButton control.

Accept amount from the users. Select Discount from the option button and display the Discount amount and the Pay-amount.

Design the form as given below. There are three TextBox. TextBox1 to enter Purchase amount. Set its Name property to TxtPurAmt

Set ReadOnly property of TextBox2& TextBox3 to True, so user can not change the content of TextBox2 & TextBox3.

Set Name property of TextBox2 to TxtDiscountAmt. & Set Name property of TextBox3 to TxtPayAmt.

Place one GroupBox. & place three RadioButton (for discount) in it. Whenever any RadioButton(Discount) is click, Its Discount amount and the Pay-amount should be display in TextBox2 & TextBox3 respectively.

image 6
‘ Coding of RadioButton1 (Write in CheckedChanged Event) 

 TxtDiscountAmt.Text = Val(TxtPurAmt.Text) * 10 / 100 
 TxtPayAmt.Text = Val(TxtPurAmt.Text) - Val(TxtDiscountAmt.Text) 
‘ Coding of RadioButton2 (Write in CheckedChanged Event) 

 TxtDiscountAmt.Text = Val(TxtPurAmt.Text) * 30 / 100 
 TxtPayAmt.Text = Val(TxtPurAmt.Text) - Val(TxtDiscountAmt.Text) 
‘ Coding of RadioButton3 (Write in CheckedChanged Event) 

 TxtDiscountAmt.Text = Val(TxtPurAmt.Text) * 50 / 100 
 TxtPayAmt.Text = Val(TxtPurAmt.Text) - Val(TxtDiscountAmt.Text) 
‘ Coding of Clear Button 

RadioButton1.Checked = False 
 RadioButton2.Checked = False 
   RadioButton3.Checked = False 
TxtPurAmt.Clear() 
TxtDiscountAmt.Clear() 
   TxtPayAmt.Clear() 
 TxtPurAmt.Focus() 
‘ Coding of Exit the form 

 Me.Close() 

Leave a Comment