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

Thread: Enter button creates sound when opening messagebox

  1. #1
    Join Date
    Mar 2015
    Posts
    1

    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.

    Code:
    private void txtResult_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Enter)
                {
                    
    
                    if (!String.IsNullOrEmpty(txtResult.Text))
                    {
                        btnCheckAnswer.PerformClick();
                        e.SuppressKeyPress = true;
                        e.Handled = true;
                    }
                   
                }
    
    
            }
    
    
    
    This is one of the btnCheckAnswer.PerformClick() actions
                }
                        }
    
                    }
    
                    else
                    {
                        numRight++;
                        MessageBox.Show("Smarty Pants, You're Right!!");
                        NextQuestion();
                        IncreaseScore();
                    }
                    return;
    
                }
    
            }
    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
    Posts
    13,277

    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
    Location
    Netherlands
    Posts
    4

    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: http://www.delphigroups.info/2/ce/524088.html

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)