数字文本框 - 变暖 [英] Numeric Textbox - getting warmer

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

问题描述

以下控制代码 - 仅允许输入

数字,退格键和小数(或句点)。

问题在于最后一个语句 - 它允许多个

小数或句点。如何将代码修改为仅允许
允许1位小数?换句话说 - 一旦用户进入一个

期间 - 没有其他人可以进入?


私有超载子TextBox1_TextChanged(ByVal发件人为

System.Object,ByVal e As

System.Windows.Forms.KeyPressEventArgs)句柄

TextBox1.KeyPress


Dim isKey As Boolean = e.KeyChar.IsDigit(e.KeyChar)

Dim isDecimal As Boolean = e.KeyChar.ToString ="。"

Dim MyChar As String = Chr(8)

Dim isBackspace As Boolean = e.KeyChar.ToString =

MyChar

如果不是isKey而不是isDecimal而不是isBackspace

然后

e.Handled = True

结束如果

结束子

谢谢。

解决方案

*" Keith" <一个******* @ discussions.microsoft.com> scripsit:

[...]


请不要多重邮件。


-

Herfried K. Wagner [MVP]

< URL:http://dotnet.mvps.org/>


Herfried,


是否真的有必要回答来自yxq的问题,他现在因此发送错误日期的消息。 Solex昨天和他确实纠正了

,因为那个帖子中有足够的消息显示他的

日期错了,这可能在我看来不再是一个意外。


我在改变他的约会时仍然没有成功,对于其他人来说也是如此。我看到了,我很清楚Solex是如何做到这一点的。


对不起Keith,我不想让这条消息保持在最前面所以我用了你的

帖子。


Cor


If isDecimal AndAlso TextBox1.Text.IndexOf("。")<> -1然后

e.Handled = True

结束如果


您知道并非所有国家/地区都使用。 ;作为

小数点分隔符,对吗?改为使用此常量:

System.Globalization.CultureInfo.CurrentCulture.Nu mberFormat.NumberDecimalSe

parator


/ claes

" Keith" <一个******* @ discussions.microsoft.com>在消息中写道

news:17 ***************************** @ phx.gbl ...

以下控制代码 - 仅允许输入数字,退格和小数(或句点)。
问题在于最后一个陈述 - 它允许多个小数或句点。如何将代码修改为仅允许1位小数?换句话说 - 一旦用户进入一个
期间 - 没有其他人可以输入?

私有超载Sub TextBox1_TextChanged(ByVal发送者为
System.Object,ByVal e As
System.Windows.Forms.KeyPressEventArgs)句柄
TextBox1.KeyPress

Dim isKey As Boolean = e.KeyChar.IsDigit(e.KeyChar)
Dim isDecimal As Boolean = e.KeyChar.ToString ="。"
Dim MyChar As String = Chr(8)
Dim isBackspace As Boolean = e.KeyChar.ToString =
MyChar
如果不是isKey And Not isDecimal而不是isBackspace
然后
e.Handled = True
结束如果


谢谢。



The following control code - only allows for the entry of
numbers, backspace, and decimals (or periods). The
problem lies in the last statement - it allows multiple
decimals or periods. How would I modify the code to only
allow 1 decimal? In other words - once a user entered one
period - no others could be entered?

Private Overloads Sub TextBox1_TextChanged(ByVal sender As
System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles
TextBox1.KeyPress

Dim isKey As Boolean = e.KeyChar.IsDigit(e.KeyChar)
Dim isDecimal As Boolean = e.KeyChar.ToString = "."
Dim MyChar As String = Chr(8)
Dim isBackspace As Boolean = e.KeyChar.ToString =
MyChar
If Not isKey And Not isDecimal And Not isBackspace
Then
e.Handled = True
End If
End Sub

thank you.

解决方案

* "Keith" <an*******@discussions.microsoft.com> scripsit:
[...]

No multiposts, please.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


Herfried,

Is it really necessary to answer questions from yxq, he is now consequently
sending messages with wrong dates. Solex did correct that yesterday with him
and because there were enough messages in that thread which showed that his
date was wrong, that this can be in my opinion not be anymore an accident.

I still am not successfol in changing his date, what is as well for others I
saw, I am currious how Solex did that.

Sorry Keith, I did not wanted this message to stay on top so I used your
thread.

Cor


If isDecimal AndAlso TextBox1.Text.IndexOf(".") <> -1 Then
e.Handled = True
End If

You do know that not all countries use "." as
the decimal separator, right? Use this constant instead:
System.Globalization.CultureInfo.CurrentCulture.Nu mberFormat.NumberDecimalSe
parator

/claes
"Keith" <an*******@discussions.microsoft.com> wrote in message
news:17*****************************@phx.gbl...

The following control code - only allows for the entry of
numbers, backspace, and decimals (or periods). The
problem lies in the last statement - it allows multiple
decimals or periods. How would I modify the code to only
allow 1 decimal? In other words - once a user entered one
period - no others could be entered?

Private Overloads Sub TextBox1_TextChanged(ByVal sender As
System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles
TextBox1.KeyPress

Dim isKey As Boolean = e.KeyChar.IsDigit(e.KeyChar)
Dim isDecimal As Boolean = e.KeyChar.ToString = "."
Dim MyChar As String = Chr(8)
Dim isBackspace As Boolean = e.KeyChar.ToString =
MyChar
If Not isKey And Not isDecimal And Not isBackspace
Then
e.Handled = True
End If
End Sub

thank you.



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

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