简体   繁体   English

如何关闭Gtk#Window

[英]How can I close Gtk# Window

I have 2 fullscreen window in my Gtk# application, primary and secondary. 我的Gtk#应用程序中有2个全屏窗口,主要和辅助。 I have buttonClose in second form's that click event handler must close this window and make some operation: 我有第二种形式的buttonClose,click事件处理程序必须关闭此窗口并进行一些操作:

    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. 尝试Window.Destroy()应该破坏辅助窗口的窗口。 You could also hide it with .Hide() but not sure that's your intention 您也可以使用.Hide()隐藏它,但不确定这是您的意图

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(); }; 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 (); RootWindow.Destroy();

However, ain't sure if that's the right way to do it. 但是,不确定这是否是正确的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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