Easy Way Of Working With Panel's?

A

Amy L.

I have a Windows Application that has a tree view for options on the left
side of the form and when a user selects an option it changes the panel to
the right of the tree view.

At this point I have about 15 panels that I am working with and to be honest
it is becoming more and more difficult to manage. For example in the
IDE(VS.NET 2003) if I want to make a change to a panel I have to keep moving
each panel to the back until the panel I want pops to the front.

The tab control at first appeared to be ideal for this except I have been
unable to figure out how to hide the tab labels.

I know there has to be an easy way to manage something like this.

Any advise?
Amy.
 
J

Justin Rogers

The easiest method is to derive controls and work with them each separately in
the designer.
Then instead of adding panels, add your new UserControl derived controls. If
you do this
you'll get all of the same benefits of having having panels, while your panels
will be self designable
outside of the main form.
 
B

Bent S. Lund

Hi.

I'm struggling with the exact same problem!

Do you have any pointers to samples or resources on this matter?



Regards,
Bent
 
H

Herfried K. Wagner [MVP]

* "Amy L. said:
I have a Windows Application that has a tree view for options on the left
side of the form and when a user selects an option it changes the panel to
the right of the tree view.

At this point I have about 15 panels that I am working with and to be honest
it is becoming more and more difficult to manage. For example in the
IDE(VS.NET 2003) if I want to make a change to a panel I have to keep moving
each panel to the back until the panel I want pops to the front.

Two solutions:

1. Design a usercontrol for each of the pages and instantiate the usercontrols.

2. Add a TabControl and hide the tabs by overlaying a panel, for
example.
 
J

Jay B. Harlow [MVP - Outlook]

Amy,
Normally I do as Justin suggested, otherwise as you are finding, its largely
unmanageable...

Rather then have 15 panels on a single form. I create 15 user controls, with
each user control have its own set of controls & code. Then I add the 15
user controls to the form. I would define either a base user control or an
interface that all 15 user controls implement that the form itself can use
to notify the selected option page (user control) to reset or load its
options...

This also allows you to better encapsulate the code specific to a "panel" in
its own class (user control).

Hope this helps
Jay
 
B

Bent Lund

Hi,

I am struggelig with the exact same problem!

Please let me know if you find a good solution!

I was concidering using a TABControl as a host for my various controls,
but it seems it's no way to hide the tab's..



Regards

Bent S. Lund
System Developer
MCP VB
 
J

Jon Skeet [C# MVP]

Amy L. said:
I have a Windows Application that has a tree view for options on the left
side of the form and when a user selects an option it changes the panel to
the right of the tree view.

At this point I have about 15 panels that I am working with and to be honest
it is becoming more and more difficult to manage. For example in the
IDE(VS.NET 2003) if I want to make a change to a panel I have to keep moving
each panel to the back until the panel I want pops to the front.

The tab control at first appeared to be ideal for this except I have been
unable to figure out how to hide the tab labels.

I know there has to be an easy way to manage something like this.

Just to give some radically different advice: drop the designer.

Write your GUI code by hand. Give everything readable names and XML
documentation so you know what everything means. Only bother having
instance variables for controls you need after initialisation. Split
your initialisation into methods to deal with each logical grouping of
controls.

The designer is great for seeing what "looks right", but IMO it's as
quick to write the production code by hand in the end - and far less
frustrating!
 
L

Les Smith

Amy
I solved the problem by doing two things. First, I overlay the tabs with a
Label control with border set to None.

Secondly, as to the navigation, don't use bring to front, send to back, etc.
Go the the properties dialog, select the desired tab in the dropdown list
and the desired tab will be brot to the front. The only caveat to using
tabs like this is that I have had the designer rearrange the order of the
tabs without my knowing it and that caused me real problems.

HTH
Les Smith
http://www.knowdotnet.com
 
J

John Saunders

What I do is define a panel into which to load usercontrols. I then load
them with the following code:

/// <summary>
/// Dynamically display a user control within a container
/// </summary>
/// <param name="container">The container into which to place the
control</param>
/// <param name="ctl">The user control to display</param>
/// <remarks>
/// The container is only allowed to contain a single user control, which
will fill the container.
/// </remarks>
public static void DisplayFormIn(Control container, Control ctl)
{
if (container.Controls.Count != 0)
{
Control oldCtl = container.Controls[0];
container.Controls.Clear();
oldCtl.Hide();
}

ctl.Dock = DockStyle.Fill;
ctl.Show();
container.Controls.Add(ctl);
container.BringToFront();
ctl.BringToFront();
}

You can continue to use the designer to design the individual user controls.
 
D

David Clegg

And as a slightly different technique to the UserControl one suggested
by many here, you could use separate forms to achieve the same effect.

Place one panel on your form & dock it to the forms client area. When
the user selects an option in the treeview, you can create the
appropriate form, set its parent to the panel, then show it. To make
this easier, you can store type information for each form when building
up your treeview.

It's also advisable to store reference to the currently displayed form
so you can close it when a new one needs to be shown.


--
Cheers,
David Clegg
dclegg_at_ebetonline_dot_com

Vote 1 http://cc.borland.com/codecentral/ccweb.exe/listing?id=21489 :)
Coming Soon! Google Groups searching with Dyna-extend(tm) technology!

Quality Central. The best way to bug Borland about bugs.
http://qc.borland.com

"You couldn't fool me on the foolingest day of the year with an
electrified
fooling machine." - Homer Simpson
 

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