Visual Studio 2012 - 文本框 [英] Visual studio 2012 - Text Box
本文介绍了Visual Studio 2012 - 文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
iam使用visual studio 2012,windows窗体和
i想让文本框仅用于数值,
所以任何人都知道应用的简单方法会很棒
谢谢..,
iam using visual studio 2012, windows forms &
i would like to make text boxes available for numeric values only,
so anyone know simple method to apply that will be great
thanks..,
推荐答案
你可以做到 - 这并不困难,但它有点烦人 - 但为什么不使用NumericUpDown呢?这样,它可以为您完成所有这些,您可以指定最大值和最小值,并将它转换为您的数字......
但是,如果你必须使用文本框,只需处理KeyPress事件:
You can do it - it's not difficult, but it's slightly annoying - but why not use a NumericUpDown instead? That way, it does all that for you, you can specify max and min values, and it converst it to a number for you as well...
But, if you must use a textbox, just handle the KeyPress Event:
private void myTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar))
{
e.Handled = true;
}
}
这篇关于Visual Studio 2012 - 文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文