WxScrolledWindow (putting into)

I’m having a real problem getting stuff into a WxScrolledWindow. What
I’m trying to do is use a scrolled widow to display a set records (two
elements, a StaticText label and a TextCtrl entry box) that will likely
be longer than the window (so need vertical scrolling). But I can’t get
anything into the ScrolledWindow control, everythings ends up at the top
left of the entire form, as if I haven’t placed them properly.

Does a ScrolledWindow need to be put into a sizer?
Does the Scrolled Window need a sizer inside of it?
Do items go into the ScrolledWindow directly, or do they need to be
placed into a sizer that is inside the ScrolledWindow?

I’ve tried everycombination I can think of, but have not hit upon the
correct one. No matter what I try, all “record” items end up at the top
left of the form, just as they would appear if the items had been
“defined” but not yet “placed”.

Hello Michael,

To answer your question as easily as possible, the problem you are
facing,
is that your scrolled window, needs to have a Panel or Window created
inside
of it, in order for it to work. Then if your going to have multiple
controls, and don’t want to exclusively control where they are, then you
will need to use a sizer on that Panel or Window, then all controls that
are
to be displayed in the Scrolled Window, need to have their parent set to
that Panel or Window.

An example, would be:

class MyFrame < Wx::Frame
def initialize()
super nil
@scrolled = Wx::ScrolledWindow.new(self)
@panel = Wx::Panel.new(@scrolled)
text1 = Wx::StaticText.new(@panel,-1,“Hello World”)
edit1 = Wx::TextCtrl.new(@panel,-1,"")
vbox = Wx::BoxSizer.new(Wx::VERTICAL)
vbox.add text1
vbox.add edit1, 1, Wx::ALL | Wx::EXPAND
@panel.sizer = vbox
end
end

With this design, you’ll see that text1 and edit1 are children of
@panel,
instead of MyFrame, or @scrolled. @panel is a child of @scrolled. And
you
don’t nesscarly need to create the Box Sizer before you create the
controls.
You can create the controls at any time, as long as they are assigned
to a
Box Sizer, before displaying them (Through show, or show_all methods of
Window), otherwise, they’ll just appear in the upper left hand corner.
:wink:

hth to clarify,

Mario

Mario S. wrote:

An example, would be:

class MyFrame < Wx::Frame
def initialize()
super nil
@scrolled = Wx::ScrolledWindow.new(self)
@panel = Wx::Panel.new(@scrolled)
text1 = Wx::StaticText.new(@panel,-1,“Hello World”)
edit1 = Wx::TextCtrl.new(@panel,-1,"")
vbox = Wx::BoxSizer.new(Wx::VERTICAL)
vbox.add text1
vbox.add edit1, 1, Wx::ALL | Wx::EXPAND
@panel.sizer = vbox
end
end

Thanks for the example, that makes it clear what the methodology is;
however, when I run your code I get the same results, exactly. The
StaticText is in the upper left hand corner, it is almost completely
overwritten (only the left-most pixel of the text is visible) by the
TextCtrl, which does function proprely. I can add size and position
parameters to both the StaticText and TextCtrl, but they have no effect,
the controls are always placed in the upper left-hand corner of the
frame, just where they would appear if the items had been “declared”,
but not yet “defined” as to where they appear in the “form”.

I am running on a WinXP system, using ruby 1.8.6 (2007-03-13 patchlevel
0) [i386-mswin32] and wxruby 2.0.0. Is this a version mis-match
problem?