当窗口关闭时,用户被要求保存他们编辑的文件。他们也可以选择取消退出申请。当通过Gtk#窗口调用DeleteEvent时,如何防止窗口关闭?
在WPF我可以CancelEventArgs.Cancel属性设置为true来做到这一点。在Gtk#中有等效/解决方法吗?
当窗口关闭时,用户被要求保存他们编辑的文件。他们也可以选择取消退出申请。当通过Gtk#窗口调用DeleteEvent时,如何防止窗口关闭?
在WPF我可以CancelEventArgs.Cancel属性设置为true来做到这一点。在Gtk#中有等效/解决方法吗?
您需要将DeleteEventArgs.RetVal设置为true,而不是false。从relevant Mono documentation:
为了保持Gtk.Window
从封闭,设置Gtk.DeleteEventHandler
的Gtk.DeleteEventArgs.RetVal
到true
。
从快速谷歌搜索发现,这条巨蟒的例子(link):
# When the window is requested to be closed, we need to check if they have
# unsaved work. We use this callback to prompt the user to save their work
# before they exit the application. From the "delete-event" signal, we can
# choose to effectively cancel the close based on the value we return.
def on_window_delete_event(self, widget, event, data=None):
if self.check_for_save(): self.on_save_menu_item_activate(None, None)
return False # Propogate event
希望这有助于。
将DeleteEventArgs.RetVal设置为false可防止应用程序退出,但窗口仍然消失,并调用ShowAll不会再显示它。 – weiqure 2009-06-26 18:35:24
谢谢!它不是很清楚...... – Pisu 2012-05-20 12:48:23