Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When the DeleteEvent is called by a Gtk# window, how can I prevent the window from closing?

Tags:

gtk#

When the window closes, the user is asked to save the file that they edited. They should also have an option to cancel quitting the application.

In WPF I can set the CancelEventArgs.Cancel property to true to do this. Is there an equivalent/workaround in Gtk#?

like image 422
weiqure Avatar asked Jan 24 '23 11:01

weiqure


1 Answers

You need to set the DeleteEventArgs.RetVal to true, not false. From the relevant Mono documentation:

To keep a Gtk.Window from closing, set Gtk.DeleteEventHandler's Gtk.DeleteEventArgs.RetVal to true.

like image 141
Vinay Sajip Avatar answered May 16 '23 08:05

Vinay Sajip