zoukankan      html  css  js  c++  java
  • Combobox的使用,日期选择器

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Threading;
    
    namespace Combobox
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                int year = DateTime.Now.Year;
    
                for (int i = 0; i <= 20; i++ )
                {
                    cboYear.Items.Add((year - i)+"年");
                }
    
    
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                cboYear.Items.Remove("2");
               
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                cboYear.Items.Clear();
            }
    
            private void cboYear_SelectedIndexChanged(object sender, EventArgs e)
            {
                if (cboMonth.Items.Count != 0)
                    return;
                for(int i = 1; i <= 12; i++)
                {
                    cboMonth.Items.Add(i + "月");
                }
            }
    
            private void cboMonth_SelectedIndexChanged(object sender, EventArgs e)
            {
                cboDay.Items.Clear();
                int day = 0;
    
                //cboMonth.SelectedItem.ToString() 返回1月,要去除月
                //Split(new char[] {'月'},StringSplitOptions.RemoveEmptyEntries) 返回数组
                string strMonth = cboMonth.SelectedItem.ToString().Split(new char[] {'月'},StringSplitOptions.RemoveEmptyEntries)[0];
                string strYear = cboYear.SelectedItem.ToString().Split(new char[] {'年'},StringSplitOptions.RemoveEmptyEntries)[0];
    
                int year = Convert.ToInt32(strYear);
                int month = Convert.ToInt32(strMonth);
    
                switch(month)
                {
                    case 1:
                    case 3:
                    case 5:
                    case 7:
                    case 8:
                    case 10:
                    case 12: day = 31;
                        break;
                    case 2:
                        if ((year % 400 == 0) || year % 4 == 0 && year % 100 != 0)
                            day = 29;
                        else
                            day = 28;
                        break;
                    default:
                        day = 30;
                        break;
                }
    
                for (int i = 1; i <= day; i++)
                {
                    cboDay.Items.Add(i + "日");
                }
            }
        }
    }
    

    重要属性DropDownStyle  

  • 相关阅读:
    论文阅读 | ExtremeNet:Bottom-up Object Detection by Grouping Extreme and Center Points
    论文阅读 | CornerNet:Detecting Objects as Paired Keypoints
    论文阅读 | FPN:Feature Pyramid Networks for Object Detection
    关于字符串 “*****AB**C*D*****” 中前缀、后缀和中间 '*' 的处理
    #include< > 和 #include” ” 的区别
    小朋友排队
    核桃的数量
    操作格子
    字串统计
    关联矩阵
  • 原文地址:https://www.cnblogs.com/my-cat/p/7417159.html
Copyright © 2011-2022 走看看