2
In the windowsforms
what is the simplest way to avoid typing spaces into a control maskedTextBox
?
2
In the windowsforms
what is the simplest way to avoid typing spaces into a control maskedTextBox
?
3
In the event Keydown of maskedTextBox put the following code below:
private void maskedTextBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Space)
{
e.Handled = true;
e.SuppressKeyPress = true;
return;
}
}
Thanks for the help!
1
Another mode using the Keypress event, why?
The Keypress Event will fire while the user is pressing the key, unlike what happens in Keydown.
private void maskedTextBox1_KeyPress(object sender, KeyEventArgs e) {
e.Handled = e.KeyChar == ' ';
}
Source: http://www.devmedia.com.br/forum/qual-a-diferenca-entre-o-onkeydown-e-o-onkeypress/214947
1
Maybe this will help you help me a lot in my project.
private void maskedTextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
//não permitir augumas coisas
if (char.IsLetter(e.KeyChar) || //Letras
char.IsSymbol(e.KeyChar) || //Símbolos
char.IsWhiteSpace(e.KeyChar)) //Espaço
e.Handled = true; //Não permitir
// VERIFICAR . - ; entre outros
if (!char.IsNumber(e.KeyChar) && !(e.KeyChar == ',') && !(e.KeyChar == Convert.ToChar(8)))
{
e.Handled = true;
}
//só permitir digitar uma vez a virgula
if (e.KeyChar == ','
&& (sender as TextBox).Text.IndexOf(',') > -1)
{
e.Handled = true;
}
}
Browser other questions tagged c# winforms
You are not signed in. Login or sign up in order to post.
What mask are you wearing?
– Omni