Mac. How to quit app after main window closes?

105 views
Skip to first unread message

Alexei Vinidiktov

unread,
Jan 26, 2015, 4:20:56 AM1/26/15
to eto-...@googlegroups.com
Hi,

I'm wondering how I can make an app quit when its main window closes on Mac OS X.

curtis

unread,
Jan 26, 2015, 11:08:00 AM1/26/15
to eto-...@googlegroups.com

Something like this may work, although typically applications on OS X do not quit when you close the window:

if (Platform.Instance.IsMac)
  myForm.Close += (sender, e) => Application.Instance.Quit();

Hope this helps!
Curtis.

Alexei Vinidiktov

unread,
Jan 26, 2015, 11:20:57 AM1/26/15
to eto-...@googlegroups.com
Thanks, Curtis, but I'm getting this error message: "Cannot assign to 'Close' because it is a 'method group'.

I've also tried the OnClosed and OnClosing events of the main window. There are no errors, but, strangely, they are not fired when I close the window, but only when I quit the application.

curtis

unread,
Jan 26, 2015, 11:33:40 AM1/26/15
to eto-...@googlegroups.com
Hi Alexei,

Sorry, typo'd the event, it should have been Closed.  As you noted these events don't fire on OS X by default, but you can turn those on by adding this style before your application starts in your mac app project:

Style.Add<Eto.Mac.Forms.ApplicationHandler>(null, h => h.AllowClosingMainForm = true);

Hope this helps!
Curtis.

Alexei Vinidiktov

unread,
Jan 26, 2015, 11:40:36 PM1/26/15
to eto-...@googlegroups.com
Thanks, Curtis.

Now it's working.

By the way, some Mac apps do quit when their last window is closed. For example, System Preferences, App Store.

curtis

unread,
Jan 27, 2015, 12:52:56 AM1/27/15
to eto-...@googlegroups.com
Hi Alexei,

You are right, some apps do indeed work that way.   It might be worth considering adding a feature to control this without platform-specific code, which I'll add to my list.

Thanks for the feedback!
Curtis.
Reply all
Reply to author
Forward
0 new messages