[MonoDevelop] What is the correct way of closing a Gtk dialog?

Michael Hutchinson m.j.hutchinson at gmail.com
Thu May 22 11:28:49 EDT 2008


On Thu, May 22, 2008 at 8:41 AM, Chris Howie <cdhowie at gmail.com> wrote:
> On Thu, May 22, 2008 at 7:15 AM, simon.n.lindgren at gmail.com
> <simon.n.lindgren at gmail.com> wrote:
>> I have created a dialog that I show to the user to get an input value.
>> How do I close the dialog in the correct way when the user clicks one of
>> the buttons in the dialog?
>> Currently I'm using the Destroy() method but that's not correct, is it?
>> I'm using C# and gtk-sharp.
>
> That is the correct way to close and dispose of all of the resources
> associated with a GObject, yes, and it works for GTK windows too.
> (Personally, I've always wondered why GObject doesn't implement
> IDisposable, but that's another discussion.)

Indeed. The confusing thing is that IDisposable IS implemented on GTK#
widgets but doesn't call Destroy -- and sadly, this can't be changed
without breaking backwards compatibility.

However, this needn't be the case for new widgets. The first thing I
do when subclassing Dialog is to override Dispose with a version that
calls Destroy. Then I can use the 'using' pattern:
using (MyDialog dialog = new MyDialog ()) {
    somevalue = dialog.Run ();
}

-- 
Michael Hutchinson
http://mjhutchinson.com


More information about the Monodevelop-list mailing list