-
March 27th, 2015, 06:07 AM
#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
-
March 27th, 2015, 07:14 PM
#2
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?
-
April 30th, 2015, 05:20 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|