I have a project to set up a textbox that would only include hours and minutes (With DateTimerPicker, you have to do it quietly, however, you need to click on another field to change data, and I found this very bad for the client ... < p>
In this way, I programmed a TextBox so that I would put a ":" to define it cute, without any problems.
But , when doing so accept only numbers it blocks me from using backspace (ASCII-8) ...
private void txtHoraMarcada_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(char.IsDigit(e.KeyChar)))
{
e.Handled = true;
}
else
{
TextBox mascara = sender as TextBox;
if (mascara.Text.Length == 2)
{
mascara.Text += ":";
txtHoraMarcada.SelectionStart = 3;
}
}
}
Is there anything to do with using the Keypress event for KeyDown on that occasion ??
I just needed to release to erase instead of having to select everything to give Del and write again, Thanks!