Gtk.Widget.DeleteEvent Event
Raised when the user has clicked on the "close" button in the window's frame (the button that is automatically set by the window manager).


public event DeleteEventHandler DeleteEvent


If the handler returns False, the widget will be destroyed (and the window closed), but if the handler returns True, nothing will be done. This is a good way to prevent the user from closing your application's window if there should be some cleanups first (like saving the document).

C# Example

using System;
using Gtk;

class TestClose
	public static void Main ()
		// Init Gtk#
		Application.Init ();
		// Create window
		Window win = new Window ("Test Close");
		win.SetDefaultSize (300, 300);
		// Add button
		Button button = new Button ("Close Now");
		button.Clicked += delegate { Application.Quit (); };
		win.Add (button);
		// Delete event
		win.DeleteEvent += delegate (object o, DeleteEventArgs e)
			// Cancel closing then the "Close"
			// button of the window is pressed
			e.RetVal = true;
		// Show window and run
		win.ShowAll ();
		Application.Run ();


Namespace: Gtk
Assembly: gtk-sharp (in gtk-sharp.dll)