Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a MessageBox.Show() equivelant in MonoCode

Tags:

.net

monomac

Is there an equivalent of MessageBox.Show() in MonoMac, or do I have to create a some sort of popup class specifically for this purpose?

like image 279
Dominic Zukiewicz Avatar asked May 09 '12 22:05

Dominic Zukiewicz


1 Answers

You're looking for NSAlert, which is a mostly equivalent to MessageBox.

You can show an NSAlert by using NSAlert.RunModal(), or use NSAlert.BeginSheet() if you want it to show up as a sheet on a particular window.

e.g.

var alert = new NSAlert {
    MessageText = "Hello, this is an alert!",
    AlertStyle = NSAlertStyle.Informational
};

alert.AddButton ("OK");
alert.AddButton ("Cancel");

var returnValue = alert.RunModal();
// returnValue will be 1000 for OK, 1001 for Cancel

You can take a look at how to use it a bit more from a MonoMac perspective here:

https://github.com/picoe/Eto/blob/master/Source/Eto.Platform.Mac/Forms/MessageBoxHandler.cs

like image 195
Curtis Avatar answered Nov 02 '22 09:11

Curtis