Вы можете использовать мой контроль:
''' <summary>
''' By Amen Ayach
''' Use RoundNumber property to set how many decimal after "."
''' example: RoundNumber = 3 so if you write 654.4444 so onlostFocus you'll see 654.444
''' </summary>
''' <remarks></remarks>
Public Class TBRound
Inherits TextBox
Dim Enterly As Boolean = True
Private _RoundNumber As Integer = 0
Public Property RoundNumber() As Integer
Get
Return _RoundNumber
End Get
Set(ByVal value As Integer)
_RoundNumber = value
End Set
End Property
Public Overrides Property Text() As String
Get
Return MyBase.Text
End Get
Set(ByVal value As String)
MyBase.Text = value
End Set
End Property
Public Function format_Number(ByVal nb As String, ByVal isDivided As Boolean, ByVal NumberAfterComma As Integer) As String
Dim str As String = ""
Try
Dim fromatString As String = ""
Dim nbs As String = "."
For i As Integer = 0 To NumberAfterComma - 1
nbs += "0"
Next
If isDivided Then
str = "#,###"
Else
str = "#"
End If
str += nbs
str = Format(Val(Decimal.Parse(nb.ToString())), str)
Catch
End Try
Return str
End Function
Private Sub TBRound_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
Dim allow As String = "0123456789." + ChrW(Keys.Back) + ChrW(Keys.Delete)
If Not allow.Contains(e.KeyChar) Then
e.Handled = True
End If
End Sub
Private Sub TBRound_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LostFocus, Me.Validated
Try
If Not Decimal.TryParse(MyBase.Text, New Decimal) Then
MyBase.Text = "0"
Else
ValDateMe()
End If
Catch
End Try
End Sub
Private Sub ValDateMe()
Try
Dim value = MyBase.Text
If Decimal.TryParse(MyBase.Text, New Decimal) Then
If MyBase.Text <> format_Number(MyBase.Text, False, RoundNumber) Then
MyBase.Text = format_Number(MyBase.Text, False, RoundNumber)
End If
Else
Enterly = False
MyBase.Text = "0"
Enterly = True
End If
Catch
End Try
End Sub
End Class