我创建了一个“确认退出”对话框以在退出时提示用户。我已成功将其连接到“退出”菜单命令,但我也想将其连接到窗口关闭 (X) 按钮。我怎样才能做到这一点?我有一些使用 Java Swing 的经验,为了完成这个任务,你必须在框架中添加一个窗口监听器来调用这个提示。我必须在这里做类似的事情吗?
问问题
379 次
1 回答
1
像这样做:
require 'fox16'
include Fox
class MyApp < FXMainWindow
def initialize(app)
@app = app
super(app, "Test", :height => 150, :width => 350, :opts=> DECOR_ALL)
self.connect(SEL_CLOSE, method(:on_close))
end
def create
super
show(PLACEMENT_SCREEN)
end
def on_close(sender, sel, event)
q = FXMessageBox.question(@app, MBOX_YES_NO, "Sure?", "You sure?")
if q == MBOX_CLICKED_YES
getApp().exit(0)
end
end
end
FXApp.new do |app|
MyApp.new(app)
app.create
app.run
end
于 2014-01-22T11:57:01.343 回答