An intermediate key blocks the text input and the cursor in the text, since getting the value will interfere with the caret position. Therefore, the iffy solution gets textboxbaseand sets the value of the caret itself.
private void numericUpDown_KeyUp(object sender, KeyEventArgs e)
{
try
{
NumericUpDown numericUpDownsender = (sender as NumericUpDown);
TextBoxBase txtBase = numericUpDownsender.Controls[1] as TextBoxBase;
int currentCaretPosition = txtBase.SelectionStart;
numericUpDownsender.DataBindings[0].WriteValue();
txtBase.SelectionStart = currentCaretPosition;
}
catch (Exception ex)
{
}
}
source
share