| 

.NET C# Java Javascript Exception

1
Textbox intelligent formatieren!

Hat einer eine weitere Idee zur Textboxen Formatierung - Mask (ohne Maskbox)

Code Verbesserungs würdig!

'################ Textboxen formatieren und focus setzen und nur Zahlen eingeben
Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus
If TextBox1.Text = "0,00" Then
'Entfernt die Maske, sobald sich der Mauszeiger im Textbox
TextBox1.Text = ""
End If
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim ListofChars As String = "0123456789.,"
If ListofChars.IndexOf(e.KeyChar) = -1 Then
e.Handled = True
End If
End Sub
Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.LostFocus
If TextBox1.Text = "" Then
'Setzt die Maske zurück, wenn Sie nichts in das Textfeld eingegeben haben, sobald der Mauszeiger das Textfeld verlassen hat
TextBox1.Text = "0,00"
End If
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
TextBox1.Text = TextBox1.Text.Trim
If Not TextBox1.Text = "" And Not TextBox1.Text = "0,00" Then
'Dim aDecimal As Decimal = CType(TextBox1.Text, Decimal)
Dim aDouble As Double = CType(TextBox1.Text, Double)
'TextBox1.Text = Format(aDecimal, "c").Replace("$", "")
TextBox1.Text = Format([aDouble], "c").Replace("$", "")

'TextBox1.Text = Format(Double.Parse(TextBox1.Text), "########0.00")

'Dim texto As String = TextBox1.Text
'TextBox1.Text = String.Format("{0:0,0}", Val(Replace(aDouble, ",", ".")))
End If
End Sub

Form

'---------- Textboxen 1 - 6 - 11 formatieren
TextBox1.Text = "0,00"
News:
20.07.2020
tsmeier 81 1 3
2 Antworten
0
So hier mal eine Lösung die noch nicht funktioniert mit 1.000,00

Wie schafft man das! :
6.543,21 ==> wie kann man diese punkte setzten 1000er! 9.876.543,21

Hat einer eine Lösung!!!!!

Gruss TM

' Überprüfen, ob das Flag im KeyDown-Ereignis gesetzt ist.
If acceptableKey = False Then
' Verhindern, dass das Zeichen in das Steuerelement eingegeben wird, da es nicht numerisch ist.
e.Handled = True
Return
Else
If e.KeyChar = Convert.ToChar(Keys.Back) Then
If strCurrency.Length > 0 Then
strCurrency = strCurrency.Substring(0, strCurrency.Length - 1)
End If
Else
strCurrency = strCurrency & e.KeyChar
End If
'#### Textfeld bleibt leer ""
If strCurrency.Length = 0 Then
TextBox4.Text = ""
ElseIf strCurrency.Length = 1 Then
TextBox4.Text = "0,0" & strCurrency
ElseIf strCurrency.Length = 2 Then
TextBox4.Text = "0," & strCurrency
'#### 1.234,56 6.543,21 ==> wie kann man diese punkte setzten 1000er! 9.876.543,21
ElseIf strCurrency.Length = 3 Then
TextBox4.Text = "0." & strCurrency
'######
ElseIf strCurrency.Length > 2 Then
TextBox4.Text = strCurrency.Substring(0, strCurrency.Length - 2) & "," & strCurrency.Substring(strCurrency.Length - 2)
End If
TextBox4.Select(TextBox4.Text.Length, 0)

End If
e.Handled = True
11.02.2021
tsmeier 81 1 3
0
ganz schön kompliziert
17.10.2021
computer79 1 1

Stelle deine Textbox-Frage jetzt!