主要是重写OnKeyPress事件,如果输入不正确就不接收字符。
protected override void OnKeyPress(KeyPressEventArgs e)
{
    //base.OnKeyPress(e);
    //如果是退格键
   
if (e.KeyChar == (char)Keys.Back)
    {
          return;
    }
    
//e.Handled = true;//不接受输入
    double outDb=0;
    if (double.TryParse(this.Text + e.KeyChar.ToString(), out outDb))
    { 
        e.Handled = false;
    }
    else
    {
        e.Handled = true;
    }
}
url:http://greatverve.cnblogs.com/archive/2012/07/03/NumberTextBox.html
源码:https://files.cnblogs.com/greatverve/WinControl.rar

相关文章:

  • 2021-07-12
  • 2022-02-03
  • 2022-12-23
  • 2021-10-01
猜你喜欢
  • 2021-10-10
  • 2022-12-23
  • 2022-12-23
  • 2021-09-23
相关资源
相似解决方案