1

我正在从另一个对话框中加入 Gtk.Dialog 关闭事件,如下所示:

AddTask dialog = new AddTask (task); //AddTask inherits from Gtk.Dialog
dialog.Close += HandleDialogClose;
dialog.Show();

void HandleDialogClose (object sender, EventArgs e)
{
    Refresh(); //Does some stuff in the calling dialog
}

当我关闭对话框(我在上面创建的那个)时,永远不会触发 HandleDialogClose 事件。知道为什么吗?

这是一些示例代码,我现在自己解决了。我正在登记 Close() 事件,而我应该登记 Destroyed() 事件。下面的代码现在可以工作(注释的代码是不工作的)。

using System;
using Gtk;

namespace test
{
    public partial class MainWindow: Gtk.Window
    {   
        public MainWindow (): base (Gtk.WindowType.Toplevel)
        {
            Build ();
            Button button1 = new Button();
            button1.Label = "Open About";
            this.Add(button1);
            button1.Show();
            button1.Clicked += HandleButton1Clicked;
        }

        void HandleButton1Clicked (object sender, EventArgs e)
        {
            About dialog = new About();
            //dialog.Close += HandleAboutClose;
            dialog.Destroyed += HandleAboutClose;
            dialog.Show();
        }

        protected void OnDeleteEvent (object sender, DeleteEventArgs a)
        {
            Application.Quit ();
            a.RetVal = true;
        }

        void HandleAboutClose (object sender, EventArgs e)
        {
            Console.WriteLine("About Closed");
        }
    }
}
4

1 回答 1

0

我需要使用

dialog.Destroyed += HandleAboutClose;

代替

dialog.Close += HandleAboutClose;
于 2012-06-07T16:00:21.047 回答