控件继承

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;
            }

        }


    }

}

使用该继承的控件,可以实现只允许输入数字.
原文地址:https://www.cnblogs.com/ltjabc/p/208843.html