简体   繁体   中英

How can I close Gtk# Window

I have 2 fullscreen window in my Gtk# application, primary and secondary. I have buttonClose in second form's that click event handler must close this window and make some operation:

    protected void OnButtonClose_Clicked (object sender, EventArgs e)
    {
        //some operation

        this.Dispose ();                        
    }

But window doesn't close! If I use this code in Primary window, that window will close and application will terminate. Why this code works for primary window and doesn't works for secondary? How can I close secondary window?

Try Window.Destroy() should destroy the window for the secondary window. You could also hide it with .Hide() but not sure that's your intention

After a ton of research on this I have found what seems to work correctly for me.

public WhateverWindow():base (Gtk.WindowType.TopLevel) {
DeleteEvent += delegate { Application.Quit(); };
}

try using the DeleteEvent += delegate { Application.Quit(); }; DeleteEvent += delegate { Application.Quit(); }; in your function see if that doesn't help.

use this:

protected void OnBtnCancelarClicked (object sender, EventArgs e)
{
   this.Destroy ();
}

It seems that the only method that works as expected is calling:

RootWindow.Destroy ();

However, ain't sure if that's the right way to do it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM