我是WinForms的初学者,想要学习一下相关知识,
如何禁用文本框中的空格按键?
private void TextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
// MyTextBox.Text ...?
}
非常感谢您的帮助。
我是WinForms的初学者,想要学习一下相关知识,
如何禁用文本框中的空格按键?
private void TextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
// MyTextBox.Text ...?
}
非常感谢您的帮助。
这就是您想要的,禁止所有空格。
private void TextBox_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = (e.KeyChar == (char)Keys.Space);
}
private void txt_keyPress(object sender, KeyPressEventArgs e) \
{
if ((sender as TextBox).SelectionStart == 0)
e.Handled = (e.KeyChar == (char)Keys.Space);
else
e.Handled = false;
}