ComboBox Important attribute: "DropDownStyle" Gets or sets the value of the specified combo box style.
The following is still a small program to review:
The code is as follows:
usingSystem;usingSystem.Windows.Forms;namespaceDate Selector { Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } //when the program loads, add the year Private voidForm1_Load (Objectsender, EventArgs e) { //get the current year intYear =DateTime.Now.Year; //Add year for(inti = year; I >=1949; i--) {CMBYEAR.ITEMS.ADD (i+"years"); } } //the month is loaded when a change occurs Private voidCmbyear_selectedindexchanged (Objectsender, EventArgs e) { //before adding, you should clean upcmbMonth.Items.Clear (); //Add for(inti =1; I <= A; i++) {CMBMONTH.ITEMS.ADD (i+"Month"); } } //when the month changes, load the day Private voidCmbmonth_selectedindexchanged (Objectsender, EventArgs e) {cmbDay.Items.Clear (); //get year, month stringStryear = CmbYear.SelectedItem.ToString (). Split (New Char[] {'years'}, Stringsplitoptions.removeemptyentries) [0]; stringStrmonth = CmbMonth.SelectedItem.ToString (). Split (New Char[] {'Month'}, Stringsplitoptions.removeemptyentries) [0]; //convert to integral type intYear =Convert.ToInt32 (stryear); intmonth =Convert.ToInt32 (Strmonth); //declaring a variable to represent the number of days intDays =0; Switch(month) { Case 1: Case 3: Case 5: Case 7: Case 8: Case Ten: Case A: Days= to; Break; Case 2: if(Datetime.isleapyear (year))//Judging Leap years{ days= in; } Else{ days= -; } Break; default: Days= -; Break; } for(inti =1; I <= days; i++) {CMBDAY.ITEMS.ADD (i+"Day"); } } }}
Source Code Link: http://pan.baidu.com/s/1pL9eTsf Password: Wvts
WinForm Review [2] ComboBox control