Skip to content

FAQ : Common runtime questions

Martin Corino edited this page Mar 21, 2024 · 3 revisions
     About      HowTo      User Guide      Reference documentation

Common runtime questions

How do Windows get destroyed?

Generally speaking top level windows except dialogs are destroyed when closed (or explicitly destroyed by calling #destroy) and all their child windows are destroyed at that moment.

Please see the user guide chapters wxRuby Life Cycles (especially the Windows section) and wxRuby Dialogs for detailed information.

Why does my control get so big?

Toplevel windows like Wx::Frame with a single, unique, child window will resize the child window to fill all the available space by default (irrespective of the fact whether the child window itself has any child windows or not).

That is why code like this:

    frame = Wx::Frame.new(nil, 'Test Frame')
    Wx::Button.new(frame, 'Hello world!', pos: [10,10], size: [80,30])
    frame.show

will show a frame with a button completely filling up the entire client area instead of showing a button of 80 by 30 pixels.

This is default behaviour accommodates the far more usual approach of creating frames with a Wx::Panel as its single, unique, child window into which all controls are added like this:

    frame = Wx::Frame.new(nil, 'Test Frame')
    panel = Wx::Panel.new(frame) 
    Wx::Button.new(panel, 'Hello world!', pos: [10,10], size: [80,30])
    frame.show

NOTE Be aware that fixed positioning/sizing of controls is strongly discouraged as this won’t work correctly on all platforms and on all the different screens, using different resolutions.
Please use sizers (see Wx::Sizer and related classes documentation) for positioning (and sizing) them instead.

How to create and use custom events?

See the test_event_handling regression test and/or the following samples:

  • event/event.rb ('Event samples' -> 'wxRuby event handling example')
  • event/threaded.rb ('Event samples' -> 'wxRuby threading example')

How do I control the TAB order of the window controls?

Use the Wx::Window#move_before_in_tab_order or Wx::Window#move_after_in_tab_order methods to change the position of a child window in the TAB order.
By default the TAB order is the same as the order of creation.

Why does my dialog not close after I press [ESC]?

Dialogs only close on pressing [ESC] if and only if they have a button with id Wx::ID_CANCEL.

Clone this wiki locally