CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  VB.NET

要文本框中怎样限制汉字的输入

楼主zzz111(111)2002-10-27 19:44:35 在 .NET技术 / VB.NET 提问

我想在文本框中只能输入数字,结果是除了数字外,汉字也能输入过去.因为汉字是两个字母,并且编码小于0.请问如何控制. 问题点数:50、回复次数:5Top

1 楼mynewpc(水中日月)回复于 2002-10-27 20:48:59 得分 0

只能在textchange事件里进行判断。Top

2 楼neu2002(wangminghai)回复于 2002-10-28 08:26:46 得分 0

Dim   tempNum   As   Long  
  Private   Sub   TextBox1_TextChanged(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   TextBox1.TextChanged  
  If   IsNumeric(TextBox1.Text)   =   False   Then  
  Try  
  TextBox1.Text   =   tempNum  
  Catch   ex   As   System.Exception  
   
  End   Try  
  Else  
  tempNum   =   TextBox1.Text  
  End   If  
  Top

3 楼kuailexq2000()回复于 2002-10-28 10:08:22 得分 0

Private   Sub   txtAuthorID_Validating(ByVal   sender   As   Object,   ByVal   e   As   System.ComponentModel.CancelEventArgs)   Handles   txtAuthorID.Validating  
                  'It   is   must   be   first   Validate   second   button_click,why   gctlflagarry(2)  
                  Try  
                          ValidateNumeric(txtAuthorID)  
                  Catch   ex   As   Exception  
                          '   Cancel   the   event   and   select   the   text   to   be   corrected   by   the   user.  
                          e.Cancel   =   True  
                          txtAuthorID.Select(0,   txtAuthorID.Text.Length)  
                          '   Set   the   ErrorProvider   error   with   the   text   to   display.    
                          Me.ErrorProvider1.SetError(txtAuthorID,   ex.Message)  
                  End   Try  
          End   Sub  
   
          Public   Sub   ValidateNumeric(ByVal   ctlControl   As   Control)  
                  '   The   second   validate  
                  '   Confirm   there   is   text   in   the   control.  
                  '   Not   remove   the   sub   to   modFunLib   ,because   ErrorProvider1   is   private.(after   change   is   to   public,protect)  
                  If   ctlControl.Text.Length   =   0   Then  
                          Throw   New   Exception("The   value   is   a   required   field")  
                  Else  
                          If   Not   IsNumeric(ctlControl.Text)   Then  
                                  'set   the   error  
                                  Throw   New   Exception("Please   enter   a   numeric   value.")  
                          Else  
                                  Me.ErrorProvider1.SetError(ctlControl,   "")  
                          End   If  
                  End   If  
          End   Sub  
  ---------------------------------------------------------------  
  没什么呀!?Top

4 楼luhanzhang(风雨无阻)回复于 2002-10-28 10:13:20 得分 0

正则表达式:\dTop

5 楼hcz10(方肖.net)回复于 2002-11-02 02:57:16 得分 50

Dim   tempNum   As   String  
          Dim   wei   As   Integer  
          Dim   flg   As   Boolean  
          Private   Sub   TextBox1_TextChanged(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   TextBox1.TextChanged  
                  If   TextBox1.Text   =   ""   Then  
                          Exit   Sub  
                  End   If  
                  If   flg   =   False   Then  
                          TextBox1.Text   =   tempNum  
                          TextBox1.SelectionStart   =   wei  
                  End   If  
          End   Sub  
   
   
          Private   Sub   TextBox1_KeyDown(ByVal   sender   As   Object,   ByVal   e   As   System.Windows.Forms.KeyEventArgs)   Handles   TextBox1.KeyDown  
                  flg   =   True  
                  If   wei   =   -1   Then   wei   =   0  
                  tempNum   =   TextBox1.Text  
                  Dim   x   As   Keys   =   e.KeyCode  
                  If   x   =   Keys.Back   Or   x   =   Keys.Left   Then  
                          wei   =   TextBox1.SelectionStart   -   1  
                  ElseIf   (x   >=   Keys.D0   And   x   <=   Keys.D9)   Or   (x   >=   Keys.NumPad0   And   x   <=   Keys.NumPad9)   Or   x   =   Keys.Right   Then  
                          wei   =   wei   +   1  
                  ElseIf   x   <>   Keys.Delete   Then  
                          flg   =   False  
                  End   If  
          End   SubTop

相关问题

  • 如何在只允许输入数字的文本框限制汉字的输入
  • 如何限制文本框的输入
  • 限制文本框输入只能为数字
  • html中文本框输入字符限制的问题
  • 如何在c#中 限制文本框只能输入数字
  • 一个简单问题--关于文本框 限制输入的!
  • 怎么限制文本框输入字符的字数
  • 我如何限制文本框只能输入0或1??
  • 怎么限制文本框输入的肯定是数字
  • 如何限制一个文本框输入值的范围?

关键词

  • 汉字
  • txtauthorid
  • textbox1
  • ctlcontrol
  • errorprovider
  • tempnum
  • wei
  • textchanged
  • flg
  • byval

得分解答快速导航

  • 帖主:zzz111
  • hcz10

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo