I made my own Currency TextBox, here is code:
CurrencyTextBox.Designer.vb:
Partial Class CurrencyTextBox
Inherits System.Windows.Forms.TextBox
(...)
End Class
and CurrencyTextBox.vb:
Public Class CurrencyTextBox
Protected Overrides Sub OnKeyPress(e As Windows.Forms.KeyPressEventArgs)
If Char.IsDigit(e.KeyChar) Or Char.IsControl(e.KeyChar) Or
e.KeyChar = Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator Then
MyBase.OnKeyPress(e)
Else
e.Handled = True
End If
End Sub
End Class
it works, but I don't know what to do with pasted text, there are a lot of examples here (Capture CTRL+V or paste in a textbox in .NET) how to catch CTRL+V, but no idea how to check if pasted text is "correct".
My idea is:
Dim text As String = Clipboard.GetText(TextDataFormat.Text)
For Each ch As Char In text
(...)
Next
but I thing it is not best way. Can I do it "better"?