C#maskedTextbox,如何禁用空格? [英] C# maskedTextbox, how to disable whitespaces?

查看:373
本文介绍了C#maskedTextbox,如何禁用空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法弄清楚如何禁用空格,我尝试了多种操作,是的,我的掩码是00000000000,但仍然允许空格.有人知道解决方法吗?

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

推荐答案

将KeyDown事件添加到文本框中,然后在创建的方法中添加以下代码:

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

这篇关于C#maskedTextbox,如何禁用空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆