0
I have a project to build a textbox that would only include hours and minutes (With Datetimerpicker, da para fazer tranquilo, however need to click in another field to change data, and I found this very bad for the client...
That way I programmed a Textbox to put a ":" to define it cute, without any problems.
However, when making you accept only numbers 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;
}
}
}
It has something to do with using the Keypress event for Keydown on that occasion??
Just needed release to erase instead of having to select everything to give Del and write again, Thanks!
better use a
maskedtextbox
nay ?– Rovann Linhalis
Thank you very much!
– Cassiani