/// <summary>只允许输入数字的文本框</summary>
public class TextBoxEx : TextBox
{
protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress(e);
// 只读, 不处理
if (this.ReadOnly) return;
// 特殊键(含空格), 不处理
if ((int)e.KeyChar <= 32) return;
// 非数字键, 放弃该输入
if (!char.IsDigit(e.KeyChar))
{
e.Handled = true;
return;
}
}
}