I need a textbox that will accept values in the format x.x or xx.x (i.e. 6.7, 4.4, or 10.0). I tried using a mask of "90.0" and "09.0" but they each seem to require two digits to the left of the decimal How should this mask be coded
We almost never use masked text boxes for numeric values exactly for this reason. Masked text boxes are fine if you need a specific format (SSN, phone #'s, etc), but pretty shabby if you have multiple possibilities.
We've rolled our own numeric text boxes via the keydown and keypress events with much success (e.g. checking how many digits to the left of the decimal on keypress, and checking that the key was a period, numeric, or backspace in keydown.
I agree that the design is rather weak. However You can achieve specific formatting by using a textbox and then reformatting when you leave.
Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave
Dim TestStr As String = ""
TestStr = Format(
Me.TextBox1.Text, "Short Date") Me.TextBox1.Text = TestStr End Sub Private Sub TextBox2_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.Leave Dim TestStr As String = ""
TestStr = Format(5459.4,
"##,##0.00") Me.TextBox2.Text = TestStr End Sub
These should provide a bit of a clue as to a possible way around the issue.
This seems to be by design. The documentation has a similar example:
(999)-000-0000
United States phone number, area code optional. If users do not want to enter the optional characters, they can either enter spaces or place the mouse pointer directly at the position in the mask represented by the first 0.
MaskedTextBox Question
BSHOE
Kaktusbluete
We've rolled our own numeric text boxes via the keydown and keypress events with much success (e.g. checking how many digits to the left of the decimal on keypress, and checking that the key was a period, numeric, or backspace in keydown.
Hope this helps,
Josh
f_scholer
Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave
Dim TestStr As String = ""TestStr = Format(
Me.TextBox1.Text, "Short Date") Me.TextBox1.Text = TestStr End Sub Private Sub TextBox2_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.Leave Dim TestStr As String = ""TestStr = Format(5459.4,
"##,##0.00") Me.TextBox2.Text = TestStr End SubThese should provide a bit of a clue as to a possible way around the issue.
Marc68