Platforms to show: All Mac Windows Linux Cross-Platform

NSAlertMBS class

Type Topic Plugin Version macOS Windows Linux iOS Targets
class Cocoa MBS MacCocoa Plugin 14.2 ✅ Yes ❌ No ❌ No ❌ No Desktop only
The class for a standard Cocoa alert.

Dim a As New NSAlertMBS

a.alertStyle = NSAlertMBS.NSCriticalAlertStyle
a.messageText = "Should be do it?"

Dim actionButton As NSButtonMBS = a.addButtonWithTitle("Do it!")
actionButton.hasDestructiveAction = True
actionButton.keyEquivalent = encodings.UTF8.Chr(13) // enter

Dim cancelButton As NSButtonMBS = a.addButtonWithTitle("Cancel")
cancelButton.keyEquivalent = encodings.UTF8.Chr(27) // esc

Dim e As Integer = a.runModal

If e = a.NSAlertFirstButtonReturn Then
MessageBox "Do it!"
End If

Return codes

Constant Value Description
NSAlertFirstButtonReturn 1000 First (rightmost) button
NSAlertSecondButtonReturn 1001 Second button.
NSAlertThirdButtonReturn 1002 Third button.

Alert styles.

Constant Value Description
NSCriticalAlertStyle 2 Critical Error
NSInformationalAlertStyle 1 Informational Alert
NSWarningAlertStyle 0 Warning Alert (Default style)

This class has no sub classes.

Some examples using this class:

Blog Entries

Xojo Developer Magazine

Release notes

  • Version 22.5
    • Fixed NSAlertMBS class to clear timeout after runModal, so you can reuse the alert object.
  • Version 22.1
    • Added SetTextAlignment method to NSAlertMBS class to use left text alignment for dialogs on macOS.

The items on this page are in the following plugins: MBS MacCocoa Plugin.

NSAffineTransformMBS   -   NSAnimationContextMBS

The biggest plugin in space...