Class

# MobileMessageBox

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Used to asynchronously display alerts.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                        | Type                             | Read-Only | Shared |
|---------------------------------------------|----------------------------------|-----------|--------|
| `LeftButton<mobilemessagebox.leftbutton>`   | `String</api/data_types/string>` |           |        |
| `Message<mobilemessagebox.message>`         | `String</api/data_types/string>` |           |        |
| `Name<mobilemessagebox.name>`               | `String</api/data_types/string>` | ✓         |        |
| `RightButton<mobilemessagebox.rightbutton>` | `String</api/data_types/string>` |           |        |
| `Title<mobilemessagebox.title>`             | `String</api/data_types/string>` |           |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                | Parameters                                                                   | Returns                                     | Shared |
|-------------------------------------|------------------------------------------------------------------------------|---------------------------------------------|--------|
| `Buttons<mobilemessagebox.buttons>` |                                                                              | `String()</api/data_types/string>`          |        |
|                                     | `Assigns</api/language/assigns>` value() As `String</api/data_types/string>` |                                             |        |
| `Handle<mobilemessagebox.handle>`   |                                                                              | `Ptr</api/data_types/additional_types/ptr>` |        |
| `Show<mobilemessagebox.show>`       |                                                                              |                                             |        |

## Events

<div class="rst-class">

table-centered_column_4

</div>

| Name                                | Parameters                                        | Returns |
|-------------------------------------|---------------------------------------------------|---------|
| `Closing<mobilemessagebox.closing>` |                                                   |         |
| `Opening<mobilemessagebox.opening>` |                                                   |         |
| `Pressed<mobilemessagebox.pressed>` | buttonIndex As `Integer</api/data_types/integer>` |         |

## Property descriptions

<div id="mobilemessagebox.leftbutton">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MobileMessageBox.LeftButton

**LeftButton** As `String</api/data_types/string>`

> The caption of the button on the left side of the dialog box.
>
> This is a **design-time-only** property.

<div id="mobilemessagebox.message">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MobileMessageBox.Message

**Message** As `String</api/data_types/string>`

> A longer message that appears below the title in the message box.
>
> Set the message:
>
> ``` xojo
> MessageBox1.Message = "Would you like to update this information?"
> ```

<div id="mobilemessagebox.name">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MobileMessageBox.Name

**Name** As `String</api/data_types/string>`

> The name of the control.

<div id="mobilemessagebox.rightbutton">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MobileMessageBox.RightButton

**RightButton** As `String</api/data_types/string>`

> The caption of the button on the right side of the dialog box.
>
> This is a **design-time-only** property.

<div id="mobilemessagebox.title">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MobileMessageBox.Title

**Title** As `String</api/data_types/string>`

> The title of the message box, which appears at the top.
>
> Set the title:
>
> ``` xojo
> MessageBox1.Title = "Warning"
> ```

## Method descriptions

<div id="mobilemessagebox.buttons">

<div class="rst-class">

forsearch

</div>

</div>

MobileMessageBox.Buttons

**Buttons** As `String()</api/data_types/string>`

> Gets the buttons for the message box.

**Buttons**(`Assigns</api/language/assigns>` value() As `String</api/data_types/string>`)

> Sets the buttons for the message box.
>
> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> When there are only one or two buttons, they are shown side-by-side. The first button displays as bold. When there are more than two buttons, they are shown vertically. The first button added is the default and displays as bold at the bottom. The remaining buttons are in added in order an appear above the default button.
>
> </div>
>
> Displays a message box with multiple buttons. HelloMessage is an <span class="title-ref">MobileMessageBox</span> that was dragged onto the Screen from the Library:
>
> ``` xojo
> HelloMessage.Title = "Hello"
> HelloMessage.Message = "Hello, World!"
>
> Var buttons() As String = Array("Yes", "No", "Maybe")
>
> HelloMessage.Buttons = buttons
>
> HelloMessage.Show
> ```

<div id="mobilemessagebox.handle">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MobileMessageBox.Handle

**Handle** As `Ptr</api/data_types/additional_types/ptr>`

> The handle to the underlying native OS control.

<div id="mobilemessagebox.show">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MobileMessageBox.Show

**Show**

> Displays the message box. This is asynchronous, so your code continues to run. When the user selects a button, the `Pressed<mobilemessagebox.pressed>` event handler is called.
>
> Displays a message box. HelloMessage is a <span class="title-ref">MobileMessageBox</span> that was dragged onto the Screen from the Library:
>
> ``` xojo
> HelloMessage.Title = "Hello"
> HelloMessage.Message = "Hello, World!"
> HelloMessage.Show ' Asynchronous, so code does not pause here
> ```

## Event descriptions

<div id="mobilemessagebox.closing">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MobileMessageBox.Closing

**Closing**

> Called when the control's layout is closing.

<div id="mobilemessagebox.opening">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MobileMessageBox.Opening

**Opening**

> Called when the control's layout is opening.
>
> This is where you typically put initialization code.
>
> This example in the Opening event of a label sets its text to "Hello":
>
> ``` xojo
> Me.Text = "Hello"
> ```

<div id="mobilemessagebox.pressed">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MobileMessageBox.Pressed

**Pressed**(buttonIndex As `Integer</api/data_types/integer>`)

> Called when the button at buttonIndex is selected.
>
> Displays the index of the selected button:
>
> ``` xojo
> Label1.Text = "You selected button " + buttonIndex.ToString
> ```

## Notes

<span class="title-ref">MobileMessageBox</span> is asynchronous — code after `Show<mobilemessagebox.show>` continues running immediately while the message box is displayed. Use the `Pressed<mobilemessagebox.pressed>` event handler to get the results of a button selection and to run code based on the selection.

There are two ways to use \`MobileMessageBox\`:

**Design-time control**

Drag a <span class="title-ref">MobileMessageBox</span> from the Library onto your Screen. Configure its properties in the Inspector or in code, call `Show<mobilemessagebox.show>`, and implement the `Pressed<mobilemessagebox.pressed>` event directly on the control:

``` xojo
' In the Pressed event of ConfirmMessage
Select Case buttonIndex
Case 0
  ' User tapped "Delete"
  DeleteSelectedItem
Case 1
  ' User tapped "Cancel"
End Select
```

**At runtime using AddHandler**

When you create a <span class="title-ref">MobileMessageBox</span> in code, use `AddHandler</api/language/addhandler>` to connect the `Pressed<mobilemessagebox.pressed>` event to a method:

``` xojo
Var msg As New MobileMessageBox
msg.Title = "Confirm"
msg.Message = "Are you sure you want to delete this item?"
msg.Buttons = Array("Delete", "Cancel")
AddHandler msg.Pressed, AddressOf MessageBoxPressed
msg.Show
```

The handler method signature must match the `Pressed<mobilemessagebox.pressed>` event:

``` xojo
Sub MessageBoxPressed(buttonIndex As Integer)
  If buttonIndex = 0 Then
    ' User tapped "Delete"
    DeleteSelectedItem
  End If
End Sub
```

<div class="note">

<div class="title">

Note

</div>

See the MessageBox example projects in the Xojo Examples folder for complete working examples. There is one project for Android and one for iOS.

</div>

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### iOS UI guidelines

Apple provides [user interface guidelines](https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/Alerts.html) for the text and buttons in a MessageBox.

## Compatibility

|                       |        |
|-----------------------|--------|
| **Project Types**     | Mobile |
| **Operating Systems** | All    |

<div class="seealso">

`MobileControl</api/user_interface/mobile/mobilecontrol>` parent class; `MessageBox</api/user_interface/messagebox>` method, `MobilePopupMessage</api/user_interface/mobile/mobilepopupmessage>` class, `AddHandler</api/language/addhandler>` statement.

</div>
