Question

I use a MaskedTextBox control to facilitate the entry of dates in my project. I have mtb.BeepOnError set to false. However, it makes a generic beep whenever the 'Enter' key or 'Esc' key is pressed, and this is undesirable for my application.

This seems to be the default behaviour for the MTB, so is there any way to change that?

Was it helpful?

Solution

You can try something like this:

void mtb_KeyDown(object sender, KeyEventArgs e) {
  if (e.KeyCode == Keys.Enter | e.KeyCode == Keys.Escape) {
    e.SuppressKeyPress = true;
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top