Export (0) Print
Expand All

Displaying a Message Box (Windows Phone, Windows, Xbox 360)

Describes how to show a message box.

The Complete Sample

The code in this topic shows you the technique. You can download a complete code sample for this topic, including full source code and any additional supporting files required by the sample.

You can use Guide.BeginShowMessageBox to show a system-supplied message box that displays alerts, warnings, and other information to the gamer. This is an asynchronous process for which you can use both polling and callback-style techniques to retrieve user input.

For more information about programming asynchronous methods, see Working with Asynchronous Methods in XNA Game Studio.

To show a message box

  1. Call Guide.BeginShowMessageBox to begin display of the message box.

    For example:

    List<string> MBOPTIONS = new List<string>();
    string msg = "Text that was typed on the keyboard will be displayed here.\nClick OK to continue...";
            mbTitle, msg, MBOPTIONS, 0,
            MessageBoxIcon.Alert, null, null);

    Guide.BeginShowMessageBox has two overloads, one of which takes a player index. It doesn't matter which one you choose, though you should be aware that on Windows Phone and Windows, the player index must always be PlayerIndex.One.

    The maximum number of buttons you can define for a message box varies by platform. It is currently two on Windows Phone, and three on Xbox 360 and Windows.

  2. When IASyncResult.IsCompleted is true, call Guide.EndShowMessageBox to retrieve the zero-based index of the message box button chosen by the user.

  3. For example:

    protected void GetMBResult(IAsyncResult r)
        int? b = Guide.EndShowMessageBox(r);
        gameState = 0;

Community Additions

© 2014 Microsoft