# How to set exit on close?

**URL:** <https://www.ruby-forum.com/t/how-to-set-exit-on-close/131169>\
**Category:** wxRuby\
**Created:** [March 6, 2008, 5:18pm UTC](https://www.ruby-forum.com/t/how-to-set-exit-on-close/131169 "2008-03-06T17:18:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![blitzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecae2f/32.png) [@blitzer](https://www.ruby-forum.com/u/blitzer)\
**Post date:** [March 6, 2008, 5:18pm UTC](https://www.ruby-forum.com/t/how-to-set-exit-on-close/131169/1 "2008-03-06T17:18:22Z")

</div>

I want to set close window when press ‘X’ in top-right I make wxruby GUI  
from Farpy guie but I can’t close it (when I close I must press close in  
cmd and the return -1) how can I set it??

---

<div class="post-metadata">

**Author:** ![blitzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecae2f/32.png) [@blitzer](https://www.ruby-forum.com/u/blitzer)\
**Post date:** [March 6, 2008, 5:42pm UTC](https://www.ruby-forum.com/t/how-to-set-exit-on-close/131169/2 "2008-03-06T17:42:02Z")

</div>

Pat K. wrote:

> I want to set close window when press ‘X’ in top-right I make wxruby GUI  
> from Farpy guie but I can’t close it (when I close I must press close in  
> cmd and the return -1) how can I set it??  
> I’m not sure I understand your question. Basically, if you want to have  
> the standard close button close a window, do nothing. By default, wxRuby  
> understands that the “X” button should close the window.

If you want to do some custom checking or processing when the close  
button on frame is pressed, use evt\_close to define an event handler for  
the frame.

evt\_close :on\_close

Then in your on\_close method, receive the event, then either call skip()  
or veto() to allow or disallow the event.

def on\_close(event)  
if ready\_to\_close  
event.skip()  
else  
event.veto()  
end  
end

Take a look at the samples/minimal/minimal.rb as this is demonstrated in  
there

alex

---

<div class="post-metadata">

**Author:** ![blitzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecae2f/32.png) [@blitzer](https://www.ruby-forum.com/u/blitzer)\
**Post date:** [March 6, 2008, 6:08pm UTC](https://www.ruby-forum.com/t/how-to-set-exit-on-close/131169/3 "2008-03-06T18:08:27Z")

</div>

thank you I find it 🙂
