using System;
using System.Windows.Forms;
namespace Northwind
{
/// <summary>
/// Summary description for NumericTextBox.
/// </summary>
public class NumericTextBox : TextBox
{
public NumericTextBox()
{
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar))
{
e.Handled = true;
}
}
}
}
using System.Windows.Forms;
namespace Northwind
{
/// <summary>
/// Summary description for NumericTextBox.
/// </summary>
public class NumericTextBox : TextBox
{
public NumericTextBox()
{
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar))
{
e.Handled = true;
}
}
}
}
使用该继承的控件,可以实现只允许输入数字.