禁用文本框中按键时的空白

use*_*556 3 c# textbox keypress winforms

我是 WinForms 的初学者,所以我想学习,

如何禁用文本框中的空白按键?

private void TextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    // MyTextBox.Text ...?
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激。

Cey*_*hun 6

这就是你想要的,禁止所有空格

    private void TextBox_KeyPress(object sender, KeyPressEventArgs e)
    {              
         e.Handled = (e.KeyChar == (char)Keys.Space);
    }
Run Code Online (Sandbox Code Playgroud)