我正在从另一个对话框中获取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事件。知道为什么吗?
这是一些示例代码,我现在自己解决了。当我本来应该参加Destroyed()事件时,我正在参加Close()事件。下面的代码现在可以使用(注释的代码是不起作用的。)
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");
}
}
}
答案 0 :(得分:0)
我需要使用
dialog.Destroyed += HandleAboutClose;
而不是
dialog.Close += HandleAboutClose;