Basic C # basics 11 check box
Application of check box--Questionnaire survey
- Implementation description: Through a questionnaire survey of gender and the way home after work, click the Submit button to display the submitted information through a message box. The result of the operation is as shown (Figure 27):
private void Buttonok_click (object sender, EventArgs e) {string sex = ""; if (Rdlmale. Checked) {sex = "male"; } else {sex = "female"; } String traffic = ""; if (checkbox1.checked) {traffic + = "" + Checkbox1.text; } if (checkbox2.checked) {traffic + = "" + Checkbox2.text; } if (checkbox3.checked) {traffic + = "" + Checkbox3.text; } if (checkbox4.checked) {traffic + = "" + Checkbox4.text; } if (checkbox5.checked) {traffic + = "" + Checkbox5.text; } if (checkbox6.checked) {traffic + = "" + Checkbox6.text; } if (checkbox7.checked) {Traffic + = " "+ Checkbox7.text; } if (checkbox8.checked) {traffic + = "" + Checkbox8.text; } MessageBox.Show ("Your gender is:" + Sex + ", the means of transport you take after work is:" + traffic); }
List Selection Control
list box
- A list box is used to represent a list of options from which the user can select one or more options. If too many items exceed the length of the list box design, the vertical scroll bar is automatically added.
- list box application-Choose your favorite tourist city, as shown in the interface (Figure 28):
private void buttonLtoR_Click(object sender, EventArgs e) { if (lstCityLeft.SelectedIndex < 0) { MessageBox.Show("请选择您喜欢的旅游城市!"); return; } string city = lstCityLeft.SelectedItem.ToString(); foreach (Object item in lstCityRight.Items) { if(city.Equals(item.ToString())){ return; } } lstCityRight.Items.Add(city); //把选择的城市添加到右边的列表中 } private void buttonRtoL_Click(object sender, EventArgs e) { //把右边选择城市从列表中移除 lstCityRight.Items.Remove(lstCityRight.SelectedItem); }
- The result of the operation is as shown (Figure 29):
Combo box
- Combo boxes combine the features of text boxes and list boxes, allowing users to enter text in a combo box or select from a list.
- Application of combo box-City selection: by selecting a province in the combo box, the list of cities is displayed in the list box below (Figure 30):
private void Cboproc_selectedindexchanged (object sender, EventArgs e) {//determines the index value of the selected item in the combo box, adds the corresponding city to the list according to the index value box, switch (cboproc.selectedindex) {case 0:listcity. Items.clear ();//Clears the contents of the list box listcity. Items.Add ("Harbin"); Listcity. Items.Add ("Jiamusi"); Listcity. Items.Add ("Mudanjiang"); Listcity. Items.Add ("Qiqihar"); Listcity. Items.Add ("Daqing"); Break Case 1:listcity. Items.clear ();//Clears the contents of the list box listcity. Items.Add ("Shenyang"); Listcity. Items.Add ("Dalian"); Listcity. Items.Add ("Anshan"); Listcity. Items.Add ("Jinzhou"); Listcity. Items.Add ("Fushun"); Break Case 2:listcity. Items.clear ();//Clears the contents of the list box listcity. Items.Add ("Changchun"); Listcity. Items.Add("Siping"); Listcity. Items.Add ("Tonghua"); Listcity. Items.Add ("Songyuan"); Break }} private void Form1_Load (object sender, EventArgs e) {cboProc.Items.Add ("Heilongjiang"); CBOPROC.ITEMS.ADD ("Liaoning"); CBOPROC.ITEMS.ADD ("Jilin"); }
- The result of the operation is as follows (Figure 31):
Civil Aviation booking system--booking system landing Form
- Requirements: Login type includes two kinds, system administrator and ordinary user; Click the Log In button to determine whether the user name, password, and login type are empty, give the appropriate message, and click the Cancel button to close the current form.
- The interface is as shown (Figure 32):
private void buttonOK_Click(object sender, EventArgs e) { if (this.username.Text.Trim().Equals(string.Empty)) { MessageBox.Show("请输入用户名!"); } else if (this.password.Text.Trim().Equals(string.Empty)) { MessageBox.Show("请输入密码!"); } else if (this.loginType.Text.Trim().Equals(string.Empty)) { MessageBox.Show("请选择登录类型!"); } else { MessageBox.Show("您输入的用户名或密码不正确!", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } private void buttonCancel_Click(object sender, EventArgs e) { this.Close(); }
Getting Started with C # basics 11