namespacewindowsformsapplication1{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } Private voidComboBox1_SelectedIndexChanged (Objectsender, EventArgs e) { intYear = Convert.ToInt32 (Combobox1.text);//defines a variable that is used to record the current selected year stringstrtext ="";//record the corresponding Zodiac for the selected year; Switch(year% A) { Case 4: strtext ="Rat"; Break; Case 5: strtext ="Cattle"; Break; Case 6: strtext ="Tiger"; Break; Case 7: strtext ="Rabbit"; Break; Case 0: strtext ="Monkey"; Break; } foreach(System.Windows.Forms.RadioButton rbtninchGroupbox1.controls)//looping through a radio button control in a GroupBox1 container { if(RBTN. Text = =strtext) rbtn. Checked=true; } } Private voidForm1_Load (Objectsender, EventArgs e) { for(inti =1990; I <=2050; i++) ComboBox1.Items.Add (i); Combobox1.text= DateTime.Now.Year.ToString ();//sets the default value for the drop-down list to the current year } }}
In the following figure, there is something in the form that can be seen in this document.
The following is irrelevant to the above:
Using System.Windows.Controls; To use this namespace, add the following selected
RadioButton Use of radio buttons