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;
    
    namespace 四则运算器
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }
    
            private void Form2_Load(object sender, EventArgs e)
            {
                //通过设置DropDownList这个枚举类型来禁止用户向ComboBox输入
                cboMonth.DropDownStyle = ComboBoxStyle.DropDownList;
    
                for(int i = 1; i <= 12; i++)
                {
                    cboMonth.Items.Add(i.ToString());
    
                }
                cboMonth.SelectedIndex = 0;
            }
    
            private void cboMonth_SelectedIndexChanged(object sender, EventArgs e)
            {
                int maxDay  = 0;
                
                switch(Convert.ToInt32(cboMonth.Text))
                {
                    case 1:
                    case 3:
                    case 5:
                    case 7:case 8:case 10: case 12:
                        maxDay = 31;
                        break;
                    case 2:
                        maxDay = 28;
                        break;
                    default:
                        maxDay = 30;
                        break;
                }
    
                cboDay.Items.Clear();
                for( int i = 1; i <= maxDay; i++)
                {
                    cboDay.Items.Add(i.ToString());
                }
    
                cboDay.SelectedIndex = 0;
    
                 
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                string str = string.Format("您选中了{0}月{1}日", cboMonth.Items[cboMonth.SelectedIndex], cboDay.Text);
                MessageBox.Show(str);
            }
        }
    }
    

      

  • 相关阅读:
    0127 date dateformat calebdar
    0126 字符串缓冲区StringBuffer类 正则表达式
    0126 String类
    0125 java API object
    0125 匿名对象 内部类 包 代码块
    0123 final关键字,static 关键字
    0123 this关键字 super关键字
    0122面向对象 构造方法
    0122面向对象3 多态
    0120 面向对象2
  • 原文地址:https://www.cnblogs.com/my-cat/p/7268411.html
Copyright © 2011-2022 走看看