public DialogResult ShowMessage(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
{
var dr = new DialogResult();
try
{
var tmp = this.Invoke(new MessageBoxShow(MessageBoxShowF), new object[] { text, caption, buttons, icon });
if (tmp != null)
{
dr = (DialogResult)tmp;
}
}
catch
{
}
return dr;
}
delegate DialogResult MessageBoxShow(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon);
DialogResult MessageBoxShowF(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
{
var dr = MessageBox.Show(text, caption, buttons, icon);
return dr;
}
调用方法:
ShowMessage("执行结果,是否成功?", "结果确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question);