// from www.danielmoth.com/Blog/
public enum MyMessageBoxResult
{
Button1,
Button2,
None
}
public static class MyMessageBox
{
///
/// Displays a message box that contains the specified text, title bar caption, and two response buttons.
///
/// The message to display.
/// The title of the message box.
/// The title of the first button.
/// The title of the second button. Pass null if you only want one button.
/// A value that indicates the user's response to the message.
public static MyMessageBoxResult 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,
0, // 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 MyMessageBoxResult.None;
else if (returned == 0)
return MyMessageBoxResult.Button1;
else if (returned == 1)
return MyMessageBoxResult.Button2;
else
return MyMessageBoxResult.None;
}
}