如何在文本框中只允许一个小数点? [英] How can I allow only one decimal point in a textbox?
本文介绍了如何在文本框中只允许一个小数点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是 C# 中的代码,文本框中只允许一个小数点:
Here is the code in C# to allow only one decimal point in a textbox:
if textbox5.text.contains(".") && e.keychar="."
{
e.handled=true
}
我必须在 VB.NET 2003 版本中使用它,但我不能使用 contains 属性.我该怎么做?
I have to use it in VB.NET 2003 version, but I can't use the contains property. How can I do this?
推荐答案
如何改用 Text.IndexOf(".")
方法?如果它返回 >=0 那么你已经有了一个小数点.
How about using the Text.IndexOf(".")
method instead? If it returns >=0 then you already have a decimal point.
If (textbox5.Text.IndexOf(".") >= 0 And e.KeyChar = ".") Then e.Handled = True
这篇关于如何在文本框中只允许一个小数点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文