$txtValue = New-Object System.Windows.Forms.MaskedTextBox
Using the mask $txtValue.Mask = "999,999,999.9999" doesn't allow me to enter, for example, 1.333 without typing 000,000,001.333 (or clicking directly at the correct position, but that's impractical). The mask $txtValue.Mask = "000,000,000.00" has almost the same issue.
I tried adding event functions, but it only edits the first number and fails:
$txtValue.add_TextChanged({
$mytxt = $txtValue.Text
$txtValue.remove_TextChanged($thisEvent)
$myValue.Text = [double]::Parse($mytxt)
$txtShareValue.add_TextChanged($thisEvent)
})
I also tried using the regex [^0-9.] and slicing the range if the text exceeds the length limit during an event, but this doesn't prevent entering multiple consecutive periods.
'{0:0##,###,###.####}' -f 1.333. Unclear how1.333becomes...001.3332(where is that2coming from) ?MaskedTextBox.Maskproperty uses a different syntax than .NET Numeric Formatting Strings which it says is in-fact derived from VB6, wow.MaskedTextBoxat all - it's intended for fixed-length, fixed-format text strings, not numeric values - for that you'd useNumericUpDown(which allows for direct input with formatting, and you can hide the up/down spinner buttons too, if you like).$myValue.Text = '{0:0##,###,###.####}' -f [double]::Parse($mytxt)