Forms Designer and Dynamic Panels

Z

Zach

I have a situation similar to what you see in Visual Studio Options
menu. A Tree View on the left, and depending on what type of node you
click it dynamically loads a panel into the right hand side of the
form.

It would be really nice if I could design all possible right hand side
panels in the forms designer, then have some way to tell the framework
"load the form represented by the class SuchAndSuchForm". What I have
to resort to currently is this:

1) Drop a panel into the right hand side of my main form.
2) Drop all the controls onto it and lay it out and everything
3) Manually edit the InitializeComponent() method and strip out all the
designer generated code into a separate method. Also remove the part
that calls Controls.Add()

This is very annoying, because I might have like 10 different types of
page I want to display on the right hand side. Not only is it a
headache stripping out code from the InitializeComponent() method that
many times, but if I want to make a change later to the layout of that
dynamic panel, it's not in the designer anymore.

I tried also making a totally new form and then change the base class
to derive from Panel instead of Form, but then it's not available in
the designer. If I could do that, then I could simply create a new
instance of that custom class type in the constructor. I also tried
leaving it as base class Form, but Form doesn't have a Dock attribute
which I would like to set to Fill since I use a splitter in the middle.

You'd think this would be a fairly common paradigm, Visual Studio
itself uses it.

Any suggestions?
Thanks
 
G

Guest

Hey Zach,

Looks like what you're problem can be easily solved using UserControls.
This way you can create a user control for each type of "page" you are
wanting to show depending on the treeview node selected. I would recommend
either adding several of those to your project, of if you're looking to
inherite from the Panel control and are using VS 2005 you can also use
Inherited User Controls. Here is a link to a user control page that might
help get you started. Hope this helps!

http://msdn.microsoft.com/library/d...l/vbconwfcusercontrolsintechnologypreview.asp
 
Z

Zach

This worked well, thansk for your advice. The problem I run into now
is that I'd like the dynamic panel on the right of the tree view to
fill the area on the right hand side. The tree view and right hand
side are separated by a splitter and when the splitter is adjusted I'd
like for the right hand side to adjust as well. Normally what I'd do
is simply set the Dock property of the right hand side to
DockStyle.Fill. There is no designer support apparently for setting
DockProperty of a UserControl, but I just went ahead and set it
manually in code to DockStyle.Fill. It fills the entire page, not just
the part to the right of the splitter, and the tree view and splitter
are drawn on top of part of the dynamic panel. Is there any way to get
this to behave the way I would expect? For reference, TreeView.Dock =
Left, Splitter.Dock = Left, RightHandSidePanel.Dock = Fill
 

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