option button Group Control (OptionGroup), or "radio button group", is one of the common controls of VFP. In the basic course of VFP-radio button group the article has given the common properties and methods of the control, and gives an example of binding the ControlSource property of the control to a field in the table. This article complements an example of programming the Click event for the control, running the following diagram:
The circumference or area of a rectangle can be computed on the basis of the user's choice in the above figure. The production steps are as follows:
A new form, set its Caption property value to "programming Getting started-compute rectangle perimeter and area", and AutoCenter property value to. T.,height property value set to 235,width property value set to 280, saved as "calculate the perimeter and area of the rectangle. Scx".
Add two label controls to the form: Label1 and Label2, set their Caption property values to "Please enter Long:" and "Enter width:", AutoSize property values are set to. T.,backstyle property values are set to 0-transparent.
Third, add two text box controls to the right of the label control Text1 and Text2, which correspond in turn to Label1 and Label2.
Add an Option button group control below the label control and the text box control Optiongroup1, first set its AutoSize property value to the. T.,buttoncount property value set to 3, and then right-click the option button Group control to select the Edit command, In its editing state, drag the three option buttons horizontally, and then select the three option buttons, setting their Caption property values to perimeter, area, and perimeter and area, as shown in the following figure:
Five, add two label controls below the option button Group control: Label3 and Label4, set their Visible property value to. f.; Add a command button control to the right of the label control Command1 and set its Caption property value to exit. To resize and position the controls appropriately, the form designer is shown in the following illustration:
Vi. Add event code:
(a) Option button group Optiongroup1 Click event code:
thisform.label3.visible=.t.
thisform.label4.visible=.t.
A=2* (Val (thisform.text1.value) +val (thisform.text2.value))
b=val (thisform.text1.value) *val ( Thisform.text2.value) do
case this.value=1 thisform.label3.caption= "the circumference of the rectangle is:" +str (a)
thisform.label4.caption= ""
case this.value=2
thisform.label4.caption= "The area of the rectangle is:" +str (b)
thisform.label3.caption= "
case this.value=3 thisform.label3.caption=" the perimeter of the rectangle is: "+str (a)
Thisform.label4.caption= "The area of the rectangle is:" +str (b)
endcase
(ii) command button Command1 Click event Code: Thisform.release
Run "calculate rectangular circumference and area. Scx".
This example is relatively simple, the code in the win2003+vfp6.0 environment debugging pass.
See the full set of "rookie also learn VFP" tutorial