数字文本框 [英] Numeric TextBox

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

问题描述

进出口新的节目,我不很懂,但我正在做一个计算器,我想用一个文本框,只有acepts数和小数,而当从剪贴板用户粘贴文本的文本框中删除任何文字字符,如在MS计算值

Im new to programming and I dont know very much about but I'm making a calculator, and i want to use a textbox that only acepts numbers and decimals, and when the user paste text from the clipboard the textbox deletes any literal characters, like the MS calc.

请花时间来解释每一部分,所以我可以学习或写出来,并告诉我要搜索什么。

Please take the time to explain each part so I can learn or write it and tell me what to search.

感谢

编辑:我会让它更加具体:

I'll make it more specific:

我如何可以在C#中的数字文本框?我用的蒙面文本框,但它不会采取小数。

How can I make a numeric textbox in C#? I've used the masked textbox but it wont take decimals.

我读过有关超载安其preSS方法,因此将纠正任何错误的字符,但我不知道该去做的事情。

I've read things about overloading the OnKeyPress method so it will correct any wrong characters but I dont know to do it.

推荐答案

最简单的方法:)

这是你的文本框重点preSS事件

on Keypress event on your textbox

if ((e.KeyChar <= 57 && e.KeyChar >= 48) || e.KeyChar == 13 || e.KeyChar == 8)
{
}
else
{
     e.Handled = true;
}

这篇关于数字文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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