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

推荐订阅源

WordPress大学
WordPress大学
Microsoft Security Blog
Microsoft Security Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
V
Visual Studio Blog
宝玉的分享
宝玉的分享
IT之家
IT之家
人人都是产品经理
人人都是产品经理
T
The Blog of Author Tim Ferriss
I
InfoQ
B
Blog RSS Feed
T
Threatpost
博客园_首页
M
MIT News - Artificial intelligence
Spread Privacy
Spread Privacy
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Know Your Adversary
Know Your Adversary
U
Unit 42
Engineering at Meta
Engineering at Meta
C
Cyber Attacks, Cyber Crime and Cyber Security
月光博客
月光博客
Scott Helme
Scott Helme
T
Tor Project blog
有赞技术团队
有赞技术团队
AWS News Blog
AWS News Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Last Week in AI
Last Week in AI
S
Schneier on Security
Vercel News
Vercel News
博客园 - Franky
C
Cybersecurity and Infrastructure Security Agency CISA
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
L
LangChain Blog
爱范儿
爱范儿
Google DeepMind News
Google DeepMind News
The GitHub Blog
The GitHub Blog
雷峰网
雷峰网
Latest news
Latest news
C
CXSECURITY Database RSS Feed - CXSecurity.com
Hugging Face - Blog
Hugging Face - Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
G
GRAHAM CLULEY
S
Security Affairs
A
About on SuperTechFans
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
大猫的无限游戏
大猫的无限游戏
W
WeLiveSecurity
Cisco Talos Blog
Cisco Talos Blog
罗磊的独立博客

博客园 - 孙英雄

C# 窗体抖动 “嵌入式资源”的调用 - 孙英雄 - 博客园 SQL2000与Oracle的分布式操作 只能输入数字的TextBox DevExpress7.3.4部分控件继承后无法编辑解决方案 Mssql安全设置 .NET中如何生成静态页 - 孙英雄 - 博客园 ASP.NET跨页面传值技巧总结 预报:卡巴斯基v6.0个人版KEY获取器---修正版 - 孙英雄 - 博客园 动态读取App.Config WEB开发调试利器:Firebug SQL函数 关注SharpDevelop的一些问题 又一款Auto病毒专杀工具,可解决双击无法打开盘符的问题 Office2007体验及下载 简单讲述基于SQL SERVER 分页的存储过程 Access中的模糊查询 - 孙英雄 - 博客园 DataGrid控件排序方法 Asp.net中的常用小技巧
只能输入数字的TextBox---补充
孙英雄 · 2008-02-15 · via 博客园 - 孙英雄

原代码:

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            
if(!char.IsDigit(e.KeyChar)) e.Handled = true;
            
//'\b'是退格键值
            if(e.KeyChar=='\b'||e.KeyChar=='.') e.Handled = false;
        }

以上代码是无法限制全角数字输入的.而在项目中全角数字是不能算真正的数字,因为在参加计算时全角可能会出错.
修改的代码:

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            
//全角占一个汉字,半角点半个汉字,所以在字节上是不同的
            
//全角数字"KeyChar"=2,半解数字"KeyChar"=1
            byte[] array = System.Text.Encoding.Default.GetBytes(e.KeyChar.ToString());
            
//array.LongLength,而不是array.Length
            if (!char.IsDigit(e.KeyChar)|| array.LongLength==2) e.Handled = true;
            
//'\b'是退格键值
            if (e.KeyChar == '\b' || e.KeyChar == '.') e.Handled = false;
             
        }