C# maskedTextbox, how to disable whitespaces?
问题 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; } } 来源