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  

  • 相关阅读:
    机器学习中 margin loss 、hinge loss 和 ramp loss 的区别
    ML 论文中 用到的 temperature
    对一系列 pickle load 进行解包,只保留最后几个
    Linux 常用命令速览
    Numpy 的 dtype 和 astype 的区别
    远程配置 tensorflow 环境
    pytorch 的一些坑
    Conda 配置虚拟 pytorch 环境 和 Tensorflow 环境
    Ubuntu 远程离线配置 pytorch 运行环境
    3.Vue起步
  • 原文地址:https://www.cnblogs.com/my-cat/p/7417159.html
Copyright © 2011-2022 走看看