A
Aaron Smith
I found an quick and dirty example of a numeric text box that converts
the string to a currency mask.. Here is the code:
Public Class NumericMaskedTextBox
Inherits System.Windows.Forms.TextBox
Private Sub NumericMaskedTextBox_KeyPress(ByVal sender As Object,
ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
'the key press is not in the string (of numerals)
If InStr(1, "0123456789.", e.KeyChar, CompareMethod.Text) = 0 Then
If AscW(e.KeyChar) <> Keys.Back Then
'the key press is not enter or delete either
'so say we have handled it
e.Handled = True
End If
Else
If InStr(1, ".", e.KeyChar, CompareMethod.Text) > 0 Then
If InStr(1, Me.Text, ".", CompareMethod.Text) > 0 Then
e.Handled = True
End If
End If
End If
End Sub
Private Sub NumericMaskedTextBox_GotFocus(ByVal sender As Object,
ByVal e As System.EventArgs) Handles MyBase.GotFocus
Text = Text.Replace("$", "")
End Sub
End Class
I have a question..
I have this data bound to a field. When the form loads, I would like it
to have the $ in the textbox... Basically, setting the format to
currency.. Is there an event in the textbox I could snag that will do this?
Thanks,
Aaron
the string to a currency mask.. Here is the code:
Public Class NumericMaskedTextBox
Inherits System.Windows.Forms.TextBox
Private Sub NumericMaskedTextBox_KeyPress(ByVal sender As Object,
ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
'the key press is not in the string (of numerals)
If InStr(1, "0123456789.", e.KeyChar, CompareMethod.Text) = 0 Then
If AscW(e.KeyChar) <> Keys.Back Then
'the key press is not enter or delete either
'so say we have handled it
e.Handled = True
End If
Else
If InStr(1, ".", e.KeyChar, CompareMethod.Text) > 0 Then
If InStr(1, Me.Text, ".", CompareMethod.Text) > 0 Then
e.Handled = True
End If
End If
End If
End Sub
Private Sub NumericMaskedTextBox_GotFocus(ByVal sender As Object,
ByVal e As System.EventArgs) Handles MyBase.GotFocus
Text = Text.Replace("$", "")
End Sub
End Class
I have a question..
I have this data bound to a field. When the form loads, I would like it
to have the $ in the textbox... Basically, setting the format to
currency.. Is there an event in the textbox I could snag that will do this?
Thanks,
Aaron