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

When the window closes, the user is prompted to save the edited file. They should also be able to cancel the exit from the application.

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

+4
source share
2 answers

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

To close Gtk.Window , set Gtk.DeleteEventHandler Gtk.DeleteEventArgs.RetVal to true .

+6
source

Found this python example ( link ) from google quick search:

 # When the window is requested to be closed, we need to check if they have # unsaved work. We use this callback to prompt the user to save their work # before they exit the application. From the "delete-event" signal, we can # choose to effectively cancel the close based on the value we return. def on_window_delete_event(self, widget, event, data=None): if self.check_for_save(): self.on_save_menu_item_activate(None, None) return False # Propogate event 

Hope this helps.

0
source

Source: https://habr.com/ru/post/1286676/


All Articles