Search code examples
c#.net-3.5maskedtextbox

Disable MaskedTextBox sound


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?


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