首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

怎么限制 textBox1 输入的仅为阿拉伯数字

2012-09-13 
如何限制 textBox1 输入的仅为阿拉伯数字如何限制 textBox1 输入的仅为阿拉伯数字如果输入的是字母或符号,

如何限制 textBox1 输入的仅为阿拉伯数字
如何限制 textBox1 输入的仅为阿拉伯数字

如果输入的是字母或符号,出现如下图的提示:



[解决办法]

C# code
用keyDown事件 private void TextBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)        {            if (e.Key != Key.Back && e.Key < Key.D0 || e.Key > Key.D9 && e.Key < Key.NumPad0 || e.Key > Key.NumPad9)            {                e.Handled = true;            }        }
[解决办法]
探讨
C# code

用keyDown事件 private void TextBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.Key != Key.Back &amp;&amp; e.Key < Key.D0 || e.Key > Key.D9 &amp;&a……

[解决办法]
C# code
/// <summary>  /// 限制输入数字以外的字符  /// </summary>  /// <param name="sender"></param>  /// <param name="e"></param>  private void textbox_KeyPress(object sender, KeyPressEventArgs e)  {  if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && e.KeyChar != 8)  {  e.Handled = true;  }  } 

热点排行