MonoTouch Tip #1 – Creating a simple Message Box function

11 May

Even in the most simple applications you will often need to display messages to the user. Hopefully it will be just useful information and only occasionally an error message. If you have created a single view iPhone application it may be an overkill to create an error handling framework. This sample will add simple Message Box functionality to your view class.

internal enum MButtons
OK = 1,
Cancel = 2

private void MessageBox(string title, string message, MButtons buttons)
using(UIAlertView alert = new UIAlertView())
alert.Title = title;
alert.Message = message;

if((buttons & MButtons.OK) == MButtons.OK)

if((buttons & MButtons.Cancel) == MButtons.Cancel)


Here is an example using this function:

MessageBox("My Message Box",
"This could be information or error details",
MButtons.OK | MButtons.Cancel);

I have found this snippet of code extremely useful when creating a quick application or prototyping a larger interface.

Leave a comment

Posted by on May 11, 2010 in MonoTouch


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: