Class
MobileMessageBox
Description
Used to asynchronously display alerts.
Properties
Name |
Type |
Read-Only |
Shared |
|---|---|---|---|
✓ |
|||
Methods
Name |
Parameters |
Returns |
Shared |
|---|---|---|---|
Events
Name |
Parameters |
Returns |
|---|---|---|
buttonIndex As Integer |
Property descriptions
MobileMessageBox.LeftButton
LeftButton As String
The caption of the button on the left side of the dialog box.
This is a design-time-only property.
MobileMessageBox.Message
Message As String
A longer message that appears below the title in the message box.
Set the message:
MessageBox1.Message = "Would you like to update this information?"
MobileMessageBox.Name
Name As String
The name of the control.
MobileMessageBox.RightButton
RightButton As String
The caption of the button on the right side of the dialog box.
This is a design-time-only property.
MobileMessageBox.Title
Title As String
The title of the message box, which appears at the top.
Set the title:
MessageBox1.Title = "Warning"
Method descriptions
MobileMessageBox.Buttons
Buttons As String()
Gets the buttons for the message box.
Buttons(Assigns value() As String)
Sets the buttons for the message box.
Note
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.
Displays a message box with multiple buttons. HelloMessage is an MobileMessageBox that was dragged onto the Screen from the Library:
HelloMessage.Title = "Hello" HelloMessage.Message = "Hello, World!" Var buttons() As String = Array("Yes", "No", "Maybe") HelloMessage.Buttons = buttons HelloMessage.Show
MobileMessageBox.Handle
Handle As Ptr
The handle to the underlying native OS control.
MobileMessageBox.Show
Show
Displays the message box. This is asynchronous, so your code continues to run. When the user selects a button, the Pressed event handler is called.
Displays a message box. HelloMessage is a MobileMessageBox that was dragged onto the Screen from the Library:
HelloMessage.Title = "Hello" HelloMessage.Message = "Hello, World!" HelloMessage.Show ' Asynchronous, so code does not pause here
Event descriptions
MobileMessageBox.Closing
Closing
Called when the control's layout is closing.
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":
Me.Text = "Hello"
MobileMessageBox.Pressed
Pressed(buttonIndex As Integer)
Called when the button at buttonIndex is selected.
Displays the index of the selected button:
Label1.Text = "You selected button " + buttonIndex.ToString
Notes
MobileMessageBox is asynchronous — code after Show continues running immediately while the message box is displayed. Use the 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 MobileMessageBox from the Library onto your Screen. Configure its properties in the Inspector or in code, call Show, and implement the Pressed event directly on the control:
' 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 MobileMessageBox in code, use AddHandler to connect the Pressed event to a method:
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 event:
Sub MessageBoxPressed(buttonIndex As Integer)
If buttonIndex = 0 Then
' User tapped "Delete"
DeleteSelectedItem
End If
End Sub
Note
See the MessageBox example projects in the Xojo Examples folder for complete working examples. There is one project for Android and one for iOS.
iOS UI guidelines
Apple provides user interface guidelines for the text and buttons in a MessageBox.
Compatibility
Project Types |
Mobile |
Operating Systems |
All |
See also
MobileControl parent class; MessageBox method, MobilePopupMessage class, AddHandler statement.