这是我使用的方法.为了获得更好的用户体验和一致性,请考虑使用“删除”和“取消”而不是“确认”或“中止”.
public static MessagePromptResult Show(string messageBoxText,string caption,string button1,string button2) { int? returned = null; using (var mre = new System.Threading.ManualResetEvent(false)) { string[] buttons; if (button2 == null) buttons = new string[] { button1 }; else buttons = new string[] { button1,button2 }; Microsoft.Xna.Framework.GamerServices.Guide.BeginShowMessageBox( caption,messageBoxText,buttons,// can choose which button has the focus Microsoft.Xna.Framework.GamerServices.MessageBoxIcon.None,// can play sounds result => { returned = Microsoft.Xna.Framework.GamerServices.Guide.EndShowMessageBox(result); mre.Set(); // Could have done it all without blocking },null); mre.WaitOne(); } if (!returned.HasValue) return MessagePromptResult.None; else if (returned == 0) return MessagePromptResult.Button1; else if (returned == 1) return MessagePromptResult.Button2; else return MessagePromptResult.None; }
您需要将Microsoft.Xna.Framework.GamerServices的引用添加到您的项目中.
原文地址:https://www.jb51.cc/windows/364331.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。