Timer控件:
组件中的最后一个控件,功能是可以根据用户自定义的时间间隔来触发时间,不会印象窗体本身的其他事件进行。
属性:
Enable 设置控件是否启用
Interval 设置事件的频率,以毫秒为单位
事件只有一个:Tick事件
例:使用timer控件获取当前时间并即时变动
private void timer1_Tick(object sender, EventArgs e) { label1.Text = DateTime.Now.ToString("yyyy年MM月dd日hh时mm分ss秒"); }
三级联动[省,市,区]
类似地区选择,当选的某个省份,后面的下拉框相对变成对应省份的区县
实现省市区联动关键是数据库的表,[每个省内区的AreaCode列是同样的]
public Form2() { InitializeComponent(); //绑定省 comboBox1.DataSource = new ChinaData().Select("0001"); comboBox1.DisplayMember = "AreaName"; comboBox1.ValueMember = "AreaCode"; //绑定市 comboBox2.DataSource = new ChinaData().Select(comboBox1.SelectedValue.ToString()); comboBox2.DisplayMember = "AreaName"; comboBox2.ValueMember = "AreaCode"; //绑定区县 comboBox3.DataSource = new ChinaData().Select(comboBox2.SelectedValue.ToString()); comboBox3.DisplayMember = "AreaName"; comboBox3.ValueMember = "AreaCode"; } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { //绑定市 comboBox2.DataSource = new ChinaData().Select(comboBox1.SelectedValue.ToString()); comboBox2.DisplayMember = "AreaName"; comboBox2.ValueMember = "AreaCode"; } private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { //绑定区县 comboBox3.DataSource = new ChinaData().Select(comboBox2.SelectedValue.ToString()); comboBox3.DisplayMember = "AreaName"; comboBox3.ValueMember = "AreaCode"; }