1

I have a text box which creates a form when enter is pressed. It is a single line textbox.

I have suppressed the keypress and using breakpoints I have determined that the "BEEP" that is being played comes when I create a form instance...

 private void txtcust_KeyDown(object sender, KeyEventArgs e)
    {
        string searchtext;
        if (e.KeyCode == Keys.Enter)
        {
            searchtext = txtcust.Text;
            e.SuppressKeyPress = true;

            frmcustlist frmcust = new frmcustlist(searchtext);
            frmcust.ShowDialog();

        }

    }

The beep gets played after this code plays:

frmcustlist frmcust = new frmcustlist(searchtext);

I have tried numerous things including handling the key up, playing with AcceptsReturn and also multiline. Multiline works if TRUE, but then obviously the textbox now has 2 lines. Surely this isn't the answer??

Thanks for any advice Gangel

UPDATE: Added e.handled - Still got a beep/

private void txtcust_KeyDown(object sender, KeyEventArgs e)
    {
        string searchtext;
        if (e.KeyCode == Keys.Enter)
        {
            searchtext = txtcust.Text;
            e.SuppressKeyPress = true;
            e.Handled = true;


            frmcustlist frmcust = new frmcustlist(searchtext);
            frmcust.ShowDialog();

        }

    }
Glenn Angel
  • 381
  • 1
  • 3
  • 14
  • Possible duplicate of [Disable beep of enter and escape key c#](https://stackoverflow.com/questions/13952932/disable-beep-of-enter-and-escape-key-c-sharp) – Sinatr Aug 28 '17 at 14:36
  • Hi @Sinatr I dont believe this is a duplicate. My event beeping is not keypress or down or up as far as i can tell. It is the actual code for the instance creation. Even frmcust.ShowDialog isnt causing the beep. Just the instance part.. – Glenn Angel Aug 28 '17 at 14:43
  • I am sure it is. Beeping happens due to `KeyDown` event handler code, e.g. move it into button `Click` event handler and there will be no beeping anymore (unless created form produces it, but that's another story). And the answer in duplicate suggest to set `e.Handled = true`, just add this line = no more beeping. – Sinatr Aug 28 '17 at 14:49
  • Thanks @Sinatr for the responses, however i have added e.handled and i still get the beep. I did have it before, and removed it, because it didnt seem to fix the problem. – Glenn Angel Aug 28 '17 at 15:32
  • Could it have anything to do with .Text being dirty still..?? I really have no idea! – Glenn Angel Aug 28 '17 at 15:33

0 Answers0