Stacked panel controls

B

Bob Rundle

I'm trying to do something simple and can't seem to get my way with the
forms designer.

My form is divided in two: left side a tree view control, right side a
panel with splitter control inbetween. So far so good.

Now I want to stack panel controls on the right side. The idea is that as I
click on tree nodes on the left side, a particular panel is made visible.

So all the panels have to have the form as the parent. Then I
programatically set visibility of the panels in the select handler for the
tree.

I can get this working if I massage the code that the forms designer
generates. However I can't seem to drop panels into the form such that all
the panels are children of the form. Furthermore my hand massaged code is
obliterated the next time I fool with the form.

Is there another, simpler way to achieve my goals?

Regards,
Bob Rundle
 
M

Mick Doherty

Use a TabControl.
Set the TabControl's Properties as follows:
Appearance = Button.
SizeMode = Fixed.
ItemSize = 0, 1
 
B

Bob Rundle

I don't want to use a tab control. I want tab control behavoir using a tree
control.

"Mick Doherty"
 
M

Mick Doherty

Setting the Tabcontrols properties as I suggested will result in a
Tabcontrol with no Navigation Tabs. To select the appropriate TabPage you
would then simply call something like

TabControl.SelectedIndex = Treeview.SelectedNode.Index

It is a simple solution to give exactly the behaviour you desire, whilst
making DesignTime editing very uncomplicated. If you insist on using Panels
then you must just make sure that the Form is selected and not a Panel when
you add a panel to the form (click on the forms Titlebar before adding a
Panel).

When you say you Hand Massage the code what exactly do you do. If you are
deleting all the code, in the forms constructor, which adds panels to other
panels and then adding the Panels to the forms control collection, then this
should not change, although dragging Panels around may result in you
inadvertantly dropping a panel into another panel.
 
B

Bob Rundle

Right, I see that now. This is a bit of a kluge though?

I've discovered that the MDI Form is really the closest thing to what I
want. I didn't realize the tree and splitter would play nice on the MDI
Parent. It's not exactly what I want, but close enough.

Thanks for the help.

Regards,
Bob Rundle


"Mick Doherty"
 
M

Mick Doherty

If Panels is what you want then the easist way to Design them is to set
their Dock property to Fill, since that's what they'll be at runtime. When
you want to design or alter the Layout of a Panel, use the Properties Window
to select the correct Panel via the Dropdown box, then click the Forms
[Design]* Tab in the IDE, the BringToFront and SendToBack buttons will then
be active on the Layout Toolbar and you can press the BringToFront button
(don't know why MS disabled them in the first place). This way you won't be
dragging Panels around and so won't be inadvertantly dropping them onto
other Panels.
 
B

Bob Rundle

I was actually doing exactly this for a while. The problem with this
approach is that the BringToFront, SendToBack alters the Z order which which
will negatively affect the tree and splitter if you don't correct it after
edits are finished. I found this approach to simply be too tedious and
brittle to work effectively.

I was also experimenting with designing panels in separate classes. This
almost works! You can actually drag and drop controls from the toolbox on
the designer and change properties. The problem is that there is no layout
grid and so getting the panel to look right is also tedious and brittle.

I'll stick with the MDI forms approach.

Bob Rundle

"Mick Doherty"
 
M

Mick Doherty

Yes, only use the BringToFront so as the Panels are correctly docked.
You could always add code to the Panels VisibleChanged() Method to bring the
PanelToFront or call Panel.BringToFront() when you make the Panel Visible.

As for designing the Panels seperately, you can cheat. UserControls have a
proper Designer Surface. Design the Panel as a UserControl and when you've
finished laying it out, just change it to Inherit from Panel instead of
UserControl (if you specifically need a Panel instead of a usercontrol that
is).

You may be happy to hear that, after this, I'm all out of suggestions :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top