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 combox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
//通过下拉框添加数据
comboBox2.Items.Add("张三");
comboBox2.Items.Add("李四");
comboBox2.Items.Add("王五"); } private void button2_Click(object sender, EventArgs e)
{
//清除成员
comboBox2.Items.Clear();
}
}
}

DropDownStyle:控制下拉框的外观

一般给combox控件起名字时候,用cbo+****

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 Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
//在程序加载的时候 将年份添加到下拉框当中
//因为年份的加载到我们现在的时候,所以要先获得当前的年份
int year = DateTime.Now.Year;
for (int i = 1949; i <= year; i++)
{
cboYear.Items.Add(i + "年");
} }
/// <summary>
/// 当年份发生该改变的时候 加载月份
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void cboYear_SelectedIndexChanged(object sender, EventArgs e)
{
cboMonth.Items.Clear();//在每次点击选择年份的时候,应该把上一次的月份清空,不然会出现重复现象
//在点击年份下拉框选好之后,把月份加入
for (int i = 1; i <=12; i++)
{
cboMonth.Items.Add(i + "月");
}
}
/// <summary>
/// 当月份发生改变的时候加载天数
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void cboMonth_SelectedIndexChanged(object sender, EventArgs e)
{
//在点击月份之前,清空天数
cboDay.Items.Clear();
//获取年份跟月份,以此来判断天数是多少
int day = 0;
string strYear = cboYear.SelectedItem.ToString().Split(new char[] { '年' }, StringSplitOptions.RemoveEmptyEntries)[0];
string strMonth = cboMonth.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 + "日");
} }
}
}

最新文章

  1. Intel.parallel.studio.xe.2015.Update.2.ISO-TBE 下载
  2. zookeeper学习(一)安装、配置、运行
  3. Linux换源+编译内核总结
  4. 异常总结&lt;经典例题&gt;
  5. iOS 最新App提交上架流程及部分问题的解决方案2016.12.21,感谢原博主!!!
  6. javascript 数组的部分常用属性用法
  7. 回收 PV - 每天5分钟玩转 Docker 容器技术(152)
  8. &lt;数据结构基础学习&gt;(五)递归
  9. Linux一些常用操作命令
  10. ORA-28040: No matching authentication protocol
  11. git自定义项目钩子和全局钩子
  12. FortiGate路由模式--静态地址线路上网配置
  13. 《剑指offer》-找到数组中重复的数字
  14. Linux学习 : 总线-设备-驱动模型
  15. TStrings与Memo.Lines赋值的问题
  16. 【python系列】SyntaxError:Missing parentheses in call to &#39;print&#39;
  17. 设计模式之Strategy模式
  18. Python3 字典 clear()方法
  19. RS特殊报表样式需求处理
  20. azkaban平台的使用

热门文章

  1. 前端工程化筑基-Node/npm/babel/polyfill/webpack
  2. WCF 服务容器化的一些问题
  3. ★k倍区间【第八届蓝桥杯省赛C++B组,第八届蓝桥杯省赛JAVAB组】
  4. CSS 奇思妙想之酷炫倒影
  5. day10-AOP-03
  6. SpringBoot项目动态定时任务之 ScheduledTaskRegistrar(解决方案一)
  7. 浅析 SeaweedFS 与 JuiceFS 架构异同
  8. 联邦GNN综述与经典算法介绍
  9. P33_小程序的页面配置
  10. P31_全局配置 - window - 设置上拉触底的距离