专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > VB Dotnet

vb.net 千位分隔符解决办法

发布时间:2011-06-23 14:40:57 文章来源:www.iduyao.cn 采编人员:星星草
vb.net 千位分隔符
找到的资料  但是出错 
大家帮忙看看,应该怎么改?

    Dim formatflg As Boolean
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        If formatflg Then
            formatflg = False
            Exit Sub
        End If
        If Len(TextBox1.Text) < 4 Then
            Exit Sub
        End If
        Dim temp As String
        Dim temp2 As String
        Dim leftlen As Integer
        temp2 = Replace(TextBox1.Text, ",", "")
        leftlen = Len(temp2) Mod 3
        For i = 3 To Len(temp2) Step 3
            If i = 3 Then
                temp = Mid(temp2, Len(temp2) - i + 1, 3)
            Else
                temp = Mid(temp2, Len(temp2) - i + 1, 3) & "," & temp
            End If
        Next i
        If leftlen <> 0 Then
            temp = Left(String.Format(temp2, leftlen, 3)) & "," & temp
        End If

        formatflg = True
        TextBox1.Text = temp
        TextBox1.SelectionStart = Len(TextBox1.Text)

    End Sub
------最佳解决方案--------------------

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        Select Case e.KeyChar
            Case "0"c To "9"c, ChrW(Keys.Back), ChrW(Keys.Home), ChrW(Keys.Left), ChrW(Keys.Right)
            Case Else
                e.Handled = True
        End Select
    End Sub

    Dim b As Boolean
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: