[wxruby-users] Detaching Controls

Mario Steele mario at ruby-im.net
Thu Apr 10 01:37:54 EDT 2008


Another way, if your planning to re-use the control, is to call
hide()/show(false) on the button, then call layout() on the window, to
re-draw the controls.  Hide will make it invisible, so that it's no longer
there.

An example:

begin
    require 'rubygems'
rescue LoadError
end
require 'wx'

class MyFrame < Wx::Frame
    include Wx
    def initialize(*args)
        super
        @button1 = Button.new(self,1000,"Hide Me!")
        @button2 = Button.new(self,1001,"Show other button")
        hbox = BoxSizer.new(HORIZONTAL)
        hbox.add(@button1,1,ALL)
        hbox.add(@button2,1,ALL)
        set_sizer(hbox)
        evt_button(1000) do
            @button1.show(false)
            layout()
        end
        evt_button(1001) do
            @button1.show(true)
            layout()
        end
    end
end

Wx::App.run do
    MyFrame.new(nil,:title=>"Button Hiding Example",:size=>[200,60]).show()
end

L8ers,

On Wed, Apr 9, 2008 at 9:06 PM, Alex Fenton <alex at pressure.to> wrote:

> Nilu Senevi wrote:
> > Does anyone know how to detach controls from a panel or frame? What I
> > want to do is click a button and redraw a new UI without the button.
> If your layout is controlled by sizers, use Sizer#remove or
> Sizer#detach, then call destroy on the removed Window. You may need to
> call Sizer#layout afterwards to adjust to the new window contents.
>
> If not, just call Window#destroy. It's one of the rare occasions that
> calling this directly is useful.
>
> http://wxruby.rubyforge.org/doc/window.html#Window_destroy
> http://wxruby.rubyforge.org/doc/sizer.html#Sizer_remove
>
> alex
>
>
>
>
> _______________________________________________
> wxruby-users mailing list
> wxruby-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/wxruby-users
>



-- 
Mario Steele
http://www.trilake.net
http://www.ruby-im.net
http://rubyforge.org/projects/wxruby/
http://rubyforge.org/projects/wxride/
http://rubyforge.org/projects/vwmc/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/wxruby-users/attachments/20080410/5adc476a/attachment.html 


More information about the wxruby-users mailing list