文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>WinForm 中TextBox,CheckBox,RadioButton等控件的综合应用

WinForm 中TextBox,CheckBox,RadioButton等控件的综合应用

时间:2010-12-30  来源:hfliyi

和上一篇中的功能相似,代码书写如下:

代码
 1  public partial class Form1 : Form
2 {
3 public Form1()
4 {
5 InitializeComponent();
6 this.button1.Enabled = false;
7 }
8 public void ValidatingOk()
9 {
10 this.button1.Enabled = (bool)this.txtName.Tag && (bool)this.txtAddress.Tag && (bool)this.txtAge.Tag;
11 }
12 private void EmptyValidating(object sender, CancelEventArgs e)
13 {
14 TextBox tb = (TextBox)sender;
15 if (tb.Text.Length == 0)
16 {
17 tb.Tag = false;
18 tb.BackColor = Color.Red;
19 }
20 else
21 {
22 tb.Tag = true;
23 tb.BackColor = SystemColors.Window;
24 }
25 ValidatingOk();
26 }
27
28 private void txtAge_KeyPress(object sender, KeyPressEventArgs e)
29 {
30 if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8)
31 {
32 e.Handled = true;
33 }
34 }
35
36 private void txtAge_Validating(object sender, CancelEventArgs e)
37 {
38 TextBox tb = (TextBox)sender;
39 if (tb.Text.Length == 0)
40 {
41 tb.Tag = false;
42 tb.BackColor = Color.Red;
43 }
44 else
45 {
46 tb.Tag = true;
47 tb.BackColor = SystemColors.Window;
48 }
49 ValidatingOk();
50 }
51
52 private void txtAddress_TextChanged(object sender, EventArgs e)
53 {
54 TextBox tb = (TextBox)sender;
55 if (tb.Text.Length == 0)
56 {
57 tb.Tag = false;
58 tb.BackColor = Color.Red;
59 }
60 else
61 {
62 tb.Tag = true;
63 tb.BackColor = SystemColors.Window;
64 }
65 ValidatingOk();
66 }
67
68 private void button1_Click(object sender, EventArgs e)
69 {
70 this.txtOutput.Text = "";
71 this.txtOutput.Text += "姓名:" + this.txtName.Text + "\r\n" + "地址:" + this.txtAddress.Text + "\r\n" + "职位:" + (string)(this.chProgrammer.Checked ? "程序员" : "不是程序员") + "\r\n" + "年龄:" + this.txtAge.Text + "\r\n" + "性别:" + (string)(this.rbFale.Checked ? "" : "");
72
73 }
74
75 private void button2_Click(object sender, EventArgs e)
76 {
77 this.txtOutput.Text = "";
78 this.txtOutput.Text += "姓名:" + "你的姓名" + "\r\n" + "地址:" + "你的地址" + "\r\n" + "职位:" + "你的职位" + "\r\n" + "年龄:" + "你的年龄" + "\r\n" + "性别:" + "你的性别" + "\r\n";
79 }
80 }

 

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载