我显示了一个DevExpress.XtraEditors.XtraMessageBox
,警告用户发生了错误。以下是执行此操作的方法:
private void TryToExit()
{
if (ERROR OCCURRED)
{
DevExpress.XtraEditors.XtraMessageBox.Show("Name already in use!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
// Focus the textbox so its text can be selected
nameTextBox.Focus();
nameTextBox.SelectAll();
}
else
{
Close();
}
}
在两种情况下可以调用此方法:
1按下表单上的OK按钮:
private void OkButton_Click(object sender, EventArgs e)
{
TryToExit();
}
2用户在文本框中按return键
private void NameTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (nameTextBox.Focused)
{
// Try to close the dialog if the user hits the return key
if (e.KeyCode == Keys.Return)
{
TryToExit();
e.SuppressKeyPress = true;
}
}
}
当我在第一个场景中调用TryToExit()
(OK按钮)时,消息框播放声音Windows Foreground.wav
,但是当我在第二个场景中调用TryToExit()
(return键)时,消息框播放声音Windows Background.wav
。这两种不同的声音的播放方式有点烦人,我想知道是否有一种方法可以确保在这两种情况下播放相同的声音效果。
发布于 2018-07-27 18:22:56
解决方案是对消息框使用BeginInvoke()
。
BeginInvoke(new Action(() => DevExpress.XtraEditors.XtraMessageBox.Show(...));
请参阅对this answer的评论
https://stackoverflow.com/questions/51562534
复制