[Gtk-sharp-list] Newbie cuestion: delete_event of a window

Fredrik Nilsson jymdman@home.se
Fri, 16 Jul 2004 19:49:04 +0200


On fre, 2004-07-16 at 19:35 +0200, Raúl Moratalla wrote:
> Hi everybody:
> 
> I'm using the documentation of mono and there is the following example 
> of a messagedialog:
> 
> MessageDialog md = new MessageDialog (parent_window, 
>                                       DialogFlags.DestroyWithParent,
>                                    MessageType.Question, 
>                                       ButtonsType.YesNo, "Are you sure you want to quit?");
>      
> ResponseType result = (ResponseType)md.Run ();
> 
> if (result == ResponseType.Yes)
>      Application.Quit();
> else
>      md.Destroy();
> 
> This code is launched in the signal delete_event of a window but, after 
> this the window of the application is deleted. What should I do for 
> avoid it?
> 
> Best regards,
> 
> Raúl

Hi Raúl,

You need to set the RetVal property of the eventargs, like this:

void on_window_delete_event (object o, DeleteEventArgs args) {
	// Show your dialog here

	if (result == ResponseType.Yes) {
		Application.Quit();
		args.RetVal = false; // <-- Destroy window
	} else {
		md.Destroy();
		args.RetVal = true; // <-- Don't destroy window
	}
}

/Fredrik