数字文本框作为 Visual Studio 工具箱中的控件 [英] numeric-only textbox as a control in Visual Studio toolbox

查看:15
本文介绍了数字文本框作为 Visual Studio 工具箱中的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个纯数字文本框.然后我想将相同的内容添加到 Visual Studio 2008 中的控件工具箱

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 allow only numeric.

如何使其在工具箱中可用?

How can I make it available in the toolbox?

推荐答案

这是创建数字 TextBox 的方法:

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

这篇关于数字文本框作为 Visual Studio 工具箱中的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆