C# maskedTextbox, how to disable whitespaces?

2019-07-28 19:12发布

I cant figure out how to disable whitespaces, I tried multiple things, and yes my mask is 00000000000 but still it allows whitespaces. Anyone know a fix?

Not much code to show, only:

Should only allow numbers to be entered, not whitespaces too :/

enter image description here

1条回答
够拽才男人
2楼-- · 2019-07-28 19:59

Add the KeyDown Event to your textbox and then add the following Code in the created method:

private void textBox_KeyDown(object sender, KeyEventArgs e)
{
  if (e.KeyCode == Keys.Space)
  {
    e.Handled = true;
    e.SuppressKeyPress = true;
    return;
  }
}
查看更多
登录 后发表回答