numeric-only textbox as a control in Visual Studio toolbox

前端 未结 4 1443
情深已故
情深已故 2020-12-06 03:43

I would like to make one numeric-only textbox. I\'d like to then add that same to the control toolbox within Visual Studio 2008

I\'ve already built the function to a

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-06 04:19

    This is how you can create numeric TextBox:

    public class NumericTextBox : TextBox
    {
        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
            {
                e.Handled = true;
            }
            base.OnKeyPress(e);
        }
    }
    

提交回复
热议问题