Win Forms Woes

B

Brad

Background:
I've made a wizard like Win form to drive the user through some repetitive
tasks. The program has a single form with an always visible panel on the
left edge (logo etc.) and three larger panels that fill most of the
remaining form. There are some buttons (back, cancel, next) at the bottom
of the form that are not tied to any specific panel to allow the user to
make selections. Based on the users action - which button was pushed - I
want to make a specific panel visible and active.

Issue:
I thought that this would be a simple matter of changing the SetBack(),
BringToFront() and Visible = true; properties. Unfortunately, it appears
that this gets difficult if the panels are directly on top of one another.
The behavior that I'm seeing is either that the desired panel doesn't
become visible - previously one stays there - or when the previous panel
goes invisible it takes the rest of the panels with it - blank screen. Am I
missing something obvious or is this just an artifact of how these panels
are positioned. I've seen the same behavior with group boxes.

Any help would be greatly appreciated.

Brad
 
K

Kevin Spencer

Assuming that the Panels are stacked on top of one another, all you have to
do is call BringToFront() on the one you want the user to see next.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Shooter
http://unclechutney.blogspot.com

A man, a plan, a canal, a palindrome that has.. oh, never mind.
 
B

Brad

Kevin,

That's what I assumed also, but that's not the behavior I've seen. Instead
when I make the front panel either visible=false or SendToBack(), one of the
other panel goes with it. I'm wondering if .Net is making the association
that one of the panels is inside the other? That would account for this
behavior. If this is the case, is there a property that I can set to force
the parent/container to be the main form?

TIA

Brad
 
B

Brad

That's not a bad idea and I do make use of the tab control quite a bit.
However, I'm trying for a wizard look and feel so a tab control won't really
fit. What I did find out is that the development environment is making one
of the panels a child of the other once it's overlaid on top of it. I could
modify the auto-generated code, but I'm hesitant to do that. I was hoping
that there was a way to remove the parent-child relationship via a property
of method.

Brad
 
B

Bojan Mijuskovic

I was hoping that there was a way to remove the parent-child relationship
via a property of method.

From what I could understand, it seems like the panels are "nested" one in
each other. Such behavior is relatively easy to achieve in the designer, by
dragging the panel control over another - it all depends where you drop it.
To be more precise try using the keyboard to move panels after you are sure
that they all are placed on the form - not in each other.

Programmatically, you could always use .Controls.Remove(panel) of the form
on form load and .Controls.Add(panel) to add them in the order of your
preference.

BTW, wizard-like behavior is possible to emulate using TabControl. I used
this method in couple occasions and it worked OK. The point is to spread
the control over the form, just leave the bottom space for back/next/cancel
buttons. Add all the tabs you need and then use your cursor keys to move
the tabcontrol further up so the tabs will eventually become hidden. If you
don't like it that way, you could always add the panel/picturebox and dock
it to the top of the form - and then 'hide' the tabs of the tab ctrl under
it. Don't forget to anchor the tab ctrl in case the form is resizable.
Also, if CTRL+TAB key combination bothers you, try handling that too.

Hope you'll find it useful.


Regards,
Bojan Mijuskovic [MVP]
 
K

Kevin Spencer

This is an excellent point. You can verify this by looking that the
designer-generated InitializeComponent method code, which can also be
modified by hand (if you know what you're doing) to fix this.

I built an extensible Wizard Control in much the same way, using Panels of
the same size layered on top of one another, and a Collection class that
keeps track of them.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Shooter
http://unclechutney.blogspot.com

A man, a plan, a canal, a palindrome that has.. oh, never mind.
From what I could understand, it seems like the panels are "nested" one in
each other. Such behavior is relatively easy to achieve in the designer,
by dragging the panel control over another - it all depends where you drop
it. To be more precise try using the keyboard to move panels after you are
sure that they all are placed on the form - not in each other.

Bojan Mijuskovic said:
From what I could understand, it seems like the panels are "nested" one in
each other. Such behavior is relatively easy to achieve in the designer,
by dragging the panel control over another - it all depends where you drop
it. To be more precise try using the keyboard to move panels after you are
sure that they all are placed on the form - not in each other.
<snip>
 
C

Chris Dunaway

Brad said:
Background:
I've made a wizard like Win form to drive the user through some repetitive
tasks. The program has a single form with an always visible panel on the
left edge (logo etc.) and three larger panels that fill most of the
remaining form. There are some buttons (back, cancel, next) at the bottom

The way I did it was to create a form with a single "content" panel.
Then create a UserControl for each "page" of the wizard. Then you can
instantiate each one in turn and show it inside the panel. Plus, it is
easier to design each page separately without having to shuffle the
panels.

You can also do this with borderless forms instead of panels.
 

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