| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1285 人关注过本帖
标题:[求助]赋值问题
取消只看楼主 加入收藏
触电
Rank: 1
等 级:新手上路
威 望:1
帖 子:228
专家分:0
注 册:2006-7-26
收藏
 问题点数:0 回复次数:5 
[求助]赋值问题

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Ch14TextBoxTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

this.buttonOK.Enabled = false;
this.textBoxAddress.Tag = false;
this.textBoxAge.Tag = false;
this.textBoxName.Tag = false;
this.textBoxOccupation.Tag = false;

this.textBoxName.Validating += new
System.ComponentModel.CancelEventHandler(this.textBoxEmpty_Validating); //委托能够赋值给属性?这句话究竟是什么意思?

this.textBoxAddress.Validating += new
System.ComponentModel.CancelEventHandler(this.textBoxEmpty_Validating);

this.textBoxOccupation.Validating+=new
System.ComponentModel.CancelEventHandler(this.textBoxOccupation_Validating);

this.textBoxAge.Validating+=new
System.ComponentModel.CancelEventHandler(this.textBoxEmpty_Validating);

this.textBoxName.TextChanged += new
System.EventHandler(this.textBox_TextChanged);
this.textBoxAddress.TextChanged+=new
System.EventHandler(this.textBox_TextChanged);
this.textBoxAge.TextChanged+=new
System.EventHandler(this.textBox_TextChanged);
this.textBoxOccupation.TextChanged+=new
System.EventHandler(this.textBox_TextChanged);

}

private void button1_Click(object sender, EventArgs e)
{
string output;

output = "Name: " + this.textBoxName.Text + "\r\n";
output += "Address: " + this.textBoxAddress.Text + "\r\n";
output += "Occupation: " + this.textBoxOccupation.Text + "\r\n";
output += "Age: " + this.textBoxAge.Text + "\r\n";

this.textBoxOutput.Text = output;
}

private void button2_Click(object sender, EventArgs e)
{
string output;

output = "Name=Your name\r\n";
output += "Address=Your address\r\n";
output += "Occupation=Only allowed value is 'Programmer'\r\n";

this.textBoxOutput.Text = output;
}

private void textBoxEmpty_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
TextBox tb = (TextBox)sender;

if (tb.Text.Length == 0)
{
tb.BackColor = Color.Red;
tb.Tag = false;
}

else
{
tb.BackColor = System.Drawing.SystemColors.Window;
tb.Tag = true;
}

ValidateOK();

}

private void textBoxOccupation_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
TextBox tb = (TextBox)sender;

if (tb.Text.CompareTo("Programmer") == 0 || tb.Text.Length == 0)
{
tb.Tag = true;
tb.BackColor = System.Drawing.SystemColors.Window;
}

else
{
tb.Tag = false;
tb.BackColor = Color.Red;
}

ValidateOK();
}

private void textBoxAge_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8)
e.Handled = true;
}

private void textBox_TextChanged(object sender, System.EventArgs e)
{
TextBox tb = (TextBox)sender;

if (tb.Text.Length == 0 && tb != textBoxOccupation)
{
tb.Tag = false;
tb.BackColor = Color.Red;
}

else if (tb == textBoxOccupation && (tb.Text.Length != 0 && tb.Text.CompareTo("Programmer") != 0))
{
tb.Tag = false;
}

else
{
tb.Tag = true;
tb.BackColor = SystemColors.Window;
}

ValidateOK();
}

private void ValidateOK()
{
this.buttonOK.Enabled=((bool)(this.textBoxAddress.Tag)&&
(bool)(this.textBoxAge.Tag)&&
(bool)(this.textBoxName.Tag)&&
(bool)(this.textBoxOccupation.Tag));
}

private void Form1_Load(object sender, EventArgs e)
{

}


}
}

搜索更多相关主题的帖子: using 赋值 System false Tag 
2006-11-06 20:03
触电
Rank: 1
等 级:新手上路
威 望:1
帖 子:228
专家分:0
注 册:2006-7-26
收藏
得分:0 
那这句话该怎样来理解呢?
2006-11-06 20:15
触电
Rank: 1
等 级:新手上路
威 望:1
帖 子:228
专家分:0
注 册:2006-7-26
收藏
得分:0 
左边是事件..右边是委托..不太懂了
2006-11-06 21:36
触电
Rank: 1
等 级:新手上路
威 望:1
帖 子:228
专家分:0
注 册:2006-7-26
收藏
得分:0 
自动生成的时候应该是没有这个函数的
2006-11-07 12:17
触电
Rank: 1
等 级:新手上路
威 望:1
帖 子:228
专家分:0
注 册:2006-7-26
收藏
得分:0 
JINGZHAO同学..能不能回答我在上面所提的问题呢?
2006-11-07 12:18
触电
Rank: 1
等 级:新手上路
威 望:1
帖 子:228
专家分:0
注 册:2006-7-26
收藏
得分:0 
thanks....
2006-11-09 22:03
快速回复:[求助]赋值问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016915 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved