日期

 private void Form3_Load(object sender, EventArgs e)
        {
            comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
            comboBox2.DropDownStyle = ComboBoxStyle.DropDownList;
            comboBox3.DropDownStyle = ComboBoxStyle.DropDownList;
            for (int i =DateTime.Now.Year; i >1949; i--)
            {
                comboBox1.Items.Add(i+"年");
            }
            dateTimePicker1.Format = DateTimePickerFormat.Custom;
            dateTimePicker1.CustomFormat = " ";
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            comboBox2.Items.Clear();
            for (int i = 1; i < 12; i++)
            {
                comboBox2.Items.Add(i +"月");
            }
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            comboBox3.Items.Clear();
            string years = comboBox1.SelectedItem.ToString().Split(new char[] { '年' }, StringSplitOptions.RemoveEmptyEntries)[0];
            string month = comboBox2.SelectedItem.ToString().Split(new char[] { '月' }, StringSplitOptions.RemoveEmptyEntries)[0];
            int year = Convert.ToInt32(years);
            int yue = Convert.ToInt32(month);
            int day = 0;
            switch (yue)
            {
                case 1:
                case 3:
                case 5:
                case 7:
                case 8:
                case 10:
                case 12:
                    day = 31;
                    break;
                case 2:
                    if (year % 400==00 || year % 4 == 0 && year % 100 != 0)
                    {
                        day = 29;
                    }
                    else
                    {
                        day = 28;
                    }
                    break;
                default:
                    day=30;
                    break;

            }

            for (int i = 1; i <=day; i++)
            {
                comboBox3.Items.Add(i + "日");
            }
        }

//日期格式选择

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {


            dateTimePicker1.Format = DateTimePickerFormat.Short;
          string strData=  dateTimePicker1.Text;
          char[] str = { '/' };        
        string[] strResult=  strData.Split(str, StringSplitOptions.RemoveEmptyEntries);
        for (int i = 0; i < strResult.Length; i++)
        {
            textBox1.Text = strResult[0] + "-" + strResult[1] + "-" + strResult[2];
           
        }
        }

原文地址:https://www.cnblogs.com/haimingkaifa/p/5361169.html