标签:nas 绑定 内容 ble abi 引用 += reac 自己
TreeNode递归
递归:自己调用自己一层一层的把数据找出来
TreeNode:可以创建多个节点
private void button1_Click(object sender, EventArgs e) { dataBind("0001", treeView1.Nodes); } public void dataBind(string code, TreeNodeCollection tnc) { foreach (ChinaStates cs in list) { if (cs.ParentAreaCode == code) { TreeNode tn = new TreeNode(cs.AreaName); tn.Tag = cs.AreaCode; dataBind(cs.AreaCode, tn.Nodes); tnc.Add(tn); } } } string tname = ""; private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { tname = ""; getData(treeView1.SelectedNode); MessageBox.Show(tname.Substring(0, tname.Length - 3)); } public void getData(TreeNode tn) { if (tn.Parent != null) { getData(tn.Parent); } tname += tn.Text + " | "; }
邮箱验证(往邮箱里发验证码)
首先要引用命名空间
using System.Net; using System.Net.Mail;
然后在按钮里面写点击事件或者在别的里面写点击事件也可以
//创建一个空的字符串 string a = ""; private void skinButton1_Click(object sender, EventArgs e) { //创建服务器对象 SmtpClient smt = new SmtpClient("这里是域名");
//创建发件人对象 MailAddress my = new MailAddress("这里是发件人的邮箱");
//创建收件人对象 MailAddress you = new MailAddress("这里是收件人的邮箱");
//创建邮件的对象,构造函数中传入发件人和收件人 MailMessage mail = new MailMessage(my, you);//最后扔进这里面去
//设置邮箱标题 mail.Subject = "这是标题";
//创建随机验证码 string a1 = "abcdefghigklmnopqrstuvwxyzABCDEFGHIKIMNOPQRSTUVWXYZ0123456789"; Random b = new Random(); for (int i = 0; i <= 4; i++) { a += a1.Substring(b.Next(0, a1.Length), 1); }
//设置邮箱内容 mail.Body = "验证码为:" + a;
//创建互联网安全证书 NetworkCredential nwcd = new NetworkCredential("发件人邮箱", "发件人邮箱的密码");
//将证书绑定到服务器对象上,服务器验证 smt.Credentials = nwcd;
//发送验证码 smt.Send(mail);
//判断是否能走到这个地方,走到了就表示发送成功 MessageBox.Show("发送成功!"); } private void skinButton2_Click(object sender, EventArgs e) { //利用第二个TextBox判断是否输入的验证码正确 if (skinTextBox2.Text == a) { MessageBox.Show("验证成功"); } else { MessageBox.Show("失败"); } }
Timer控件
可以在用户点击完获取验证码之后开启倒计时
private void timer1_Tick(object sender, EventArgs e) { time--; button2.Text = "发送(" + time.ToString() + ")"; if (time <= 0) { button2.Text = "发送"; button2.Enabled = true; timer1.Enabled = false; } }
新用户窗体
直接在解决方案下添加用户窗体即可,注:用户窗体里面的Designer.cs组件设计器生成的代码下面的private一定要改成pubilc
剩下的直接调用即可.
2017年11月30日 C#TreeNode递归&邮箱验证&新用户窗体
标签:nas 绑定 内容 ble abi 引用 += reac 自己
原文地址:http://www.cnblogs.com/zJuevers/p/7931803.html