C# maskedTextbox, how to disable whitespaces?

拜拜、爱过 提交于 2019-12-11 05:21:30

问题


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 :/


回答1:


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;
  }
}


来源:https://stackoverflow.com/questions/44423674/c-sharp-maskedtextbox-how-to-disable-whitespaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!