You need the following event procedure at the correct place of code.
- Code: Select all
Event WindowWillClose()
'Alert("WindowWillClose")
NSApplication.Terminate(Me) ' will quit your app
End Event
Where to place depends on the creation of the window.
1) The default way:
You use
- Code: Select all
Event AwakeFromNib()
mywindow.Delegate = Me ' set the delegate of the NSWindow in code.
End Event
IBOutlet mywindow As NSWindow
Event WindowWillClose()
NSApplication.Terminate(Me)
End Event
and create a windows in Interface Builder, and connect the IBOutlet in Interface Builder. Therefore, you need additional to set the delegate of the NSWindow in code or Interface Builder.
Attached you will find a small example doing that only.
By the way, make sure that "Release When Closed" is not set in Interface Builder for your NSWindow, otherwise your app will crash.
2) If you created it in code in some code file by something like
- Code: Select all
Dim mywindow As NSWindow
the Event WindowWillClose() must be there as well and don't forget to set the delegate of the NSWindow in code as well.