自定義Text控件控件,使其衹能輸入"0123456789"

自定義一個Text控件,在其中加入以下代碼:

        #region 重寫事件
        
string sKeys = "0123456789";
        
protected override void OnKeyPress(KeyPressEventArgs e)
        {
            
base.OnKeyPress(e);

            
if ((this.SelectedText == this.Text) && this.SelectedText != "")
            {
                
if (sKeys.IndexOf(e.KeyChar) < 0)
                {
                    e.Handled 
= true;
                }
                
return;
            }          
        }   
        
#endregion


相关文章:

  • 2021-12-18
  • 2021-11-04
  • 2022-12-23
  • 2021-04-26
  • 2022-12-23
  • 2021-08-22
  • 2022-12-23
  • 2021-08-19
猜你喜欢
  • 2021-12-26
  • 2021-05-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-15
  • 2022-12-23
相关资源
相似解决方案