CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 3 of 3

Thread: Enter button creates sound when opening messagebox

  1. #1
    Join Date
    Mar 2015

    Enter button creates sound when opening messagebox

    Tried several ways, can't figure out how to disable the 'ding' sound. I know this is basic, but I really can't figure it out. Any advice is greatly appreciated

    This is my button press event.

    private void txtResult_KeyDown(object sender, KeyEventArgs e)
                if (e.KeyCode == Keys.Enter)
                    if (!String.IsNullOrEmpty(txtResult.Text))
                        e.SuppressKeyPress = true;
                        e.Handled = true;
    This is one of the btnCheckAnswer.PerformClick() actions
                        MessageBox.Show("Smarty Pants, You're Right!!");
    Last edited by Arjay; March 27th, 2015 at 07:10 PM. Reason: Added code tags

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004

    Re: Enter button creates sound when opening messagebox

    If we go by the naming convention, txtResult_KeyDown() isn't a button click event, it's a text change event for a textbox. If you need to handle a button click, then setup an OnClick handler.

    Windows will ding when you are in the middle of doing something with the keyboard, but haven't finished processing it. If you try to do something in the middle, it will ding.

    At any rate, what does btnCheckAnswer.PerformClick(); do? Are you trying to simulate a button click?

  3. #3
    Join Date
    Apr 2015

    Re: Enter button creates sound when opening messagebox

    IIRC from way back when I still did GUI coding, you need to clear the KeyCode of the KeyEventArgs. Set it to zero. But you need to use KeyPress (if that is what the event is called using C#) instead of KeyDown.

    A thread discussing the same problem using Delphi:

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)