timer控件、三级联动
timer控件:
实现时间日期自增长:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace timer控件
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); label1.Text = DateTime.Now.ToString("yyyy年MM月dd日hh时mm分ss秒");
}
//计时器
private void timer1_Tick(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToString("yyyy年MM月dd日hh时mm分ss秒");
}
}
}
抽奖设置,点击开始开始抽奖,开始按钮变为结束,点击结束,抽奖结束,结束按钮变为开始:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace timer控件
{
public partial class Form2 : Form
{
List<long> nu = new List<long>();
Random r = new Random(); public Form2()
{
InitializeComponent();
nu.Add();
nu.Add();
nu.Add();
nu.Add();
nu.Add(); }
//抽奖
bool s = false;
private void button1_Click(object sender, EventArgs e)
{
if (s)//结束抽奖
{
button1.Text = "开始";
s = false;
timer1.Enabled = false;
}
else//开始抽奖
{
button1.Text = "停止";
s = true;
timer1.Enabled = true;
}
} private void timer1_Tick(object sender, EventArgs e)
{
label2.Text= nu[r.Next(,nu.Count)].ToString();
}
}
}
作弊:
在if结束抽奖中加一句代码:
label2.text="";
三级联动:
创建实体类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace 三级联动.App_Code
{
public class china
{
public string areacode { get; set; }
public string areaname { get; set; }
public string parentareacode { get; set; } }
}
创建数据访问类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient; namespace 三级联动.App_Code
{
public class chinadata
{
SqlConnection conn = null;
SqlCommand cmd = null; public chinadata()
{
conn = new SqlConnection("server=.;database=mydb;user=sa;pwd=123");
cmd = conn.CreateCommand();
} public List<china> select(string pcode)
{
List<china> clist = new List<china>();
cmd.CommandText = "select*from ChinaStates where ParentAreaCode=@a";
cmd.Parameters.Clear();
cmd.Parameters.Add("@a",pcode);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
china c = new china();
c.areacode = dr[].ToString();
c.areaname = dr[].ToString();
c.parentareacode = dr[].ToString();
clist.Add(c);
}
}
conn.Close();
return clist;
} }
}
form1:使用selectedindexchanged事件,引用命名空间
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using 三级联动.App_Code; namespace 三级联动
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); //绑定省
comboBox1.DataSource = new chinadata().select("");
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";
}
}
}

timer控件、三级联动的更多相关文章
- 【2017-05-05】timer控件、三级联动、帐号激活权限设置
一.Timer控件 Timer实际就是一个线程控件. 属性:Enabled 是否被启用 Interval 多长时间执行一次控件中的代码 事件: Tick 事件中放要执行的代码. ...
- timer控件、三级联动、帐号激活权限设置
一.Timer控件 Timer实际就是一个线程控件. 属性:Enabled 是否被启用 Interval 多长时间执行一次控件中的代码 事件: Tick 事件中放要执行的代码. ...
- winform/timer控件/权限设置/三级联动
一.timer控件 组件--timer timer是一个线程,默认可以跨线程访问对象 属性:Enabled--可用性 Interval--间隔时间 Tick:间隔时间发生事件 二.三级联动 例: pu ...
- winform 用户控件、 动态创建添加控件、timer控件、控件联动
用户控件: 相当于自定义的一个panel 里面可以放各种其他控件,并可以在后台一下调用整个此自定义控件. 使用方法:在项目上右键.添加.用户控件,之后用户控件的编辑与普通容器控件类似.如果要在后台往窗 ...
- winform用户控件、动态创建添加控件、timer控件、控件联动
用户控件: 相当于自定义的一个panel 里面可以放各种其他控件,并可以在后台一下调用整个此自定义控件. 使用方法:在项目上右键.添加.用户控件,之后用户控件的编辑与普通容器控件类似.如果要在后台往窗 ...
- WinForm用户控件、动态创建添加控件、timer控件--2016年12月12日
好文要顶 关注我 收藏该文 徐淳 关注 - 1 粉丝 - 3 0 0 用户控件: 通过布局将多个控件整合为一个控件,根据自己的需要进行修改,可对用户控件内的所有控件及控件属性进行修 ...
- 无边框窗体和timer控件
一.无边框窗体 1.控制按钮如何制作就是放置可以点击的控件,不局限于使用按钮或是什么别的,只要放置的控件可以点击能触发点击事件就可以了 做的好看一点,就是鼠标移入(pictureBox1_MouseE ...
- C# Winform学习---MDI窗体的设计,PictureBox控件(图片上一页下一页),Timer控件,MenuStrip控件
一.MDI窗体的设计 1.MDI简介 MDI(Multiple Document Interface)就是所谓的多文档界面,与此对应就有单文档界面 (SDI), 它是微软公司从Windows 2.0下 ...
- WinForm timer控件
timer 控件:按用户定义的时间间隔引发的事件 属性: Enabled 是否启用: Interval 事件发生的事件间隔,单位是毫秒 事件只有一个:Tick 事件经过指定的时间间隔 ...
随机推荐
- bootstrap组件学习
转自http://v3.bootcss.com/components/ bootstrap组件学习 矢量图标的用法<span class="glyphicon glyphicon-se ...
- Centos 6.5升级到Git2.1.2
安装需求 # yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel# yum install gcc pe ...
- 《linux内核设计与实现》读书笔记第十八章
第18章 调试 18.1 准备开始 准备工作需要的是: 一个bug 一个藏匿bug的内核版本 相关内核代码的知识和运气 18.2 内核中的bug 内核中bug的产生原因 从明白无误的错误代码——没有把 ...
- linux下tar、zip等压缩、解压命令
.tar解包:tar xvf FileName.tar打包:tar cvf FileName.tar DirName(注:tar是打包,不是压缩!)-------------------------- ...
- jq验证码换一换
<!DOCTYPE html><html><head> <meta charset="utf-8"> <meta http-e ...
- vim - Simple commands to remove unwanted whitespace
http://vim.wikia.com/wiki/Remove_unwanted_spaces 1. manual commandremove trailing whitespace::%s/\s\ ...
- Android-项目介绍
一个.net开发人员 在了解android项目只能凭自己的理解慢慢来了! 新建项目 右击 New-JAVA Application Project 傻瓜似的下一步骤填写每一步 文件介绍 Android ...
- Java 多线程submit和execute
submit方法: public abstract class AbstractExecutorService implements ExecutorService { protected <T ...
- linux下用户账户切换
1,)当前我已经登录一个用户hadoop,我怎么切换到root账户呢(应为一般用户经常会遇到无权限修改/etc/hosts./ect/hostname等文件的权限)? 使用命令sudo su root ...
- 【Selenium】3.介绍Selenium IDE
本文供学习交流之用,没有商业用途,没有盈利. 完全是我自己为督促自己学习而翻译的.翻译的不好,见谅.来源于:http://www.guru99.com/introduction-selenuim-id ...