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 事件经过指定的时间间隔 ...
随机推荐
- lua 可变参数
问题:对可变参数传递的时候,采用如下方案: local cellData = {MsgText = msgText,Param = ...,CallBackFunc = callBackFunc,Ca ...
- Variance
http://mathworld.wolfram.com/Variance.html Variance For a single variate having a distribution with ...
- Pinyin 输入法安装 opensuse 13 gnome
1 安装 拼音输入法 zypper in pinyin (scim 包含) 2 安装包 scim,scim-m17n,scim-pinyin,scim-qtimm,scim-tables,s ...
- iOS CAShapeLayer记录
基本知识 看看官方说明: /* The shape layer draws a cubic Bezier spline in its coordinate space. * * The spline ...
- jqGrid通用编辑规则
一个将数据显示在grid中主要的原因是为了快速容易的编辑它,jqGrid支持3种编辑方法 jqGrid单元格编辑配置,事件及方法::编辑表格中的单元格 jqGrid行编辑配置:同时编辑一行中的多个单元 ...
- Python之路-python(面向对象进阶(模块的动态导入、断言、Socket Server))
模块的动态导入 断言 Socket Server 一.模块的动态导入 class C(object): def __init__(self): self.name = "zhangsan&q ...
- 关于IPv6被拒
关于IPv6被拒 App在本地IPv6的测试环境下运行一切正常,结果又是被拒,悲剧原因还是IPv6的问题;求解决方法被拒原因We discovered one or more bugs i ...
- MVC_表单和HTML辅助方法
表单的使用 action特性告知Web浏览器信息发往哪里. method特性告知浏览器使用HTTP POST 还是 HTTP GET. GET请求用于读操作, POST请求用于写操作 HTML辅助方法 ...
- 我的AngularJS 学习之旅(二)
记得某位大神说过,"时间就像海绵里的水,挤挤总是有的.".大多时候,与其说我是很忙而没时间去做自己想做的事, 倒不如说是懒得去做罢了. 废话不多说,接前一篇继续吧 3.3 指令(D ...
- 使用Go开发web服务器
原文链接 Go(Golang.org)是在标准库中提供HTTP协议支持的系统语言,通过他可以快速简单的开发一个web服务器.同时,Go语言为开发者提供了很多便利.这本篇博客中我们将列出使用Go开发HT ...