//Windows forms maskedTextBox Input Right to Left testex with '##.####' mask decimal(6,4);
private void maskedTextBoxMaskRTF_KeyPress(object sender, KeyPressEventArgs e)
{
var maskedTextBox = (MaskedTextBox)sender;
var contLit = maskedTextBox.Text.Where(ch => ".,".Contains(ch)).Count();
var value = maskedTextBox.Text.Replace(".", "").Replace(",", "") + e.KeyChar;
if (value.Length >= maskedTextBox.Mask.Length - contLit)
value = value.Substring(1);
else
while (value.Length < maskedTextBox.Mask.Length - contLit)
value = "_" + value;
maskedTextBox.Text = value;
maskedTextBox.SelectionStart = maskedTextBox.Mask.Length - 1;
maskedTextBox.SelectionLength = 1;
}
foreach (var c in form.Controls)
, test whether the current control is a TextBox usingTextBox tb = c as TextBox; if (tb != null) ...
and set the cursor position fortb
.