惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
News and Events Feed by Topic
爱范儿
爱范儿
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 叶小钗
Last Week in AI
Last Week in AI
博客园 - 三生石上(FineUI控件)
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
月光博客
月光博客
大猫的无限游戏
大猫的无限游戏
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - Franky
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 司徒正美
罗磊的独立博客
博客园 - 聂微东
T
Troy Hunt's Blog
美团技术团队
IT之家
IT之家
A
Arctic Wolf
腾讯CDC
雷峰网
雷峰网
SecWiki News
SecWiki News
博客园_首页
L
LINUX DO - 最新话题
Cloudbric
Cloudbric
量子位
N
News and Events Feed by Topic
小众软件
小众软件
C
CXSECURITY Database RSS Feed - CXSecurity.com
Cyberwarzone
Cyberwarzone
J
Java Code Geeks
V
V2EX
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Latest news
Latest news
Webroot Blog
Webroot Blog
F
Fortinet All Blogs
P
Privacy International News Feed
NISL@THU
NISL@THU
Google Online Security Blog
Google Online Security Blog
WordPress大学
WordPress大学
PCI Perspectives
PCI Perspectives
GbyAI
GbyAI
宝玉的分享
宝玉的分享
阮一峰的网络日志
阮一峰的网络日志
S
Secure Thoughts
Simon Willison's Weblog
Simon Willison's Weblog
P
Palo Alto Networks Blog
V
Visual Studio Blog

博客园 - dn

[2008年]毕业论文格式要求 《面向.NET的XML程序设计》MAC模拟题 《基于C#的Windows应用程序设计》MCP认证考试模拟题 第六章课后习题及答案 第五章课后习题及答案 第四章课后习题及答案 毕业设计论文封面模板 在C#程序设计中使用Win32 API .NET中常用的连接字符串 第三章课后习题和答案 第三章例题:文件许可 第三章例题:为控件添加设计时支持 第三章例题:重载控件属性 第三章例题:自定义控件 毕业论文格式 第二章课后习题及答案 第二章例题:动态添加控件 [2007年]毕业设计:bluehill人事管理系统 快速导航
第二章例题:验证处理
dn · 2007-03-18 · via 博客园 - dn

对教材2.6.2、2.6.3、2.6.4部分进行的例题演示,代码如下:

 1//对控件验证事件的处理
 2        private void minValueTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
 3        {
 4            if(Convert.ToInt32(minValueTextBox.Text) >= Convert.ToInt32(maxValueTextBox.Text))
 5            {
 6                e.Cancel = true;
 7                MessageBox.Show("You must enter a minimum value that is less than the Maximum value");
 8            }

 9        }

10
11//利用ErrorProvider控件完成验证
12        private void textBox1_Validating(object sender, System.ComponentModel.CancelEventArgs e)
13        {
14            try
15            {
16                int x= Int32.Parse(textBox1.Text);
17                errorProvider1.SetError(textBox1,"");
18            }

19            catch
20            {
21                errorProvider1.SetError(textBox1,"Not a integer value.");
22            }

23        }

 1//窗体级别的验证
 2        private void btnValidate_Click(object sender, System.EventArgs e)
 3        {
 4            foreach(System.Windows.Forms.Control aControl in this.Controls)
 5            {
 6                if(aControl is System.Windows.Forms.TextBox && aControl.Text=="")
 7                {
 8                    aControl.Focus();
 9                    return;
10                }

11            }

12            MessageBox.Show("通过了验证!");
13
14        }

完整例题代码下载:Validating.rar