有没有办法在 Visual Basic 中的 TextBox 上制作千位分隔符?请告诉我有什么方法?我提前说很多谢谢..
问问题
6452 次
2 回答
0
由于您使用的是文本框,因此我建议您也验证用户输入。这是一个简单的验证方法,它也将使用 2 个小数位和千位分隔符格式化字符串:
Private Sub TextBox1_Validating(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
Try
TextBox1.Text = FormatNumber(TextBox1.Text, 2, TriState.False, , TriState.True)
Catch ex As Exception
MessageBox.Show("Only digits and/or a decimal please.")
e.Cancel = True
End Try
End Sub
如果文本框中的字符串在失去焦点时可以解析为将被格式化的数字。如果不是,则显示通知用户错误的消息框,并且焦点返回到文本框。
有关验证事件的MSDN文章
MSDN关于Try...Catch...Final 声明的文章
有关 FormatNumber 的MSDN文章
很难看出如何将数百万个字符串输入到单行文本框中,但这是另一种方式:
Private Sub TextBox1_Validating(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
If Double.TryParse(TextBox1.Text, vbNull) Then
TextBox1.Text = FormatNumber(TextBox1.Text, 2, TriState.False, , TriState.True)
Else
MessageBox.Show("Only digits and/or a decimal please.")
e.Cancel = True
End If
End Sub
于 2013-07-24T08:53:41.487 回答
-1
在Visual Basic中将千位分隔符放在TextBox上的最懒惰的方法
- 右键单击TextBox 。
- 转到属性。
- 搜索 ThousandsSeparat 并设置为true。
希望它有所帮助。
于 2019-08-27T04:00:20.440 回答