views:

347

answers:

5

I have an application that uses a frame extensively and needs to hide/show certain buttons depending on which form is active at the time. In order to keep the buttons neat and organized appropriately, I have put them on panels and show or hide the panels as needed for each form. My problem is when each form is initially created, the panels on the frame are out of order even though I am explicitly telling them which order to put themselves into. After I hide and re-show the form, the panels are in the correct order. Any suggestions on how to keep them in the proper order from the very beginning?

+3  A: 

Instead of giving the panels explicit positions, try giving them alignments. They tend to stick better than way, and they do a better job of resizing if you resize the form.

Mason Wheeler
Gave alignments originally. Found I had to adjust them.
Tom
+1  A: 

You can also try using a stackpanel (or was it flowpanel?) as parent for the panels. Then you will have a order instead of a position to manipulate.

Vegar
+1  A: 

Maybe you can have a look at the DevExpress LAyoutControl? It helps us creating interfaces that always look good, no matter if we show or hide certain groups / panels. It even allows for run-time customization of the interface, if you want that!

birger
DevExpress rules. They have only the one disadvantage: price.
smok1
That is true. However, I think their components are worth the investment. A new version of the LayoutControl is coming up. This version will also support tabs. I'm really looking forward to this!
birger
A: 

You may try to organize them by coordinates i.e.: setting Top and Left. Unless your panels are aligned, this will always work (but it takes bit lot of work).

smok1
A: 

I had this problem and I found that the solution was to do this in FormCreate (or in a CMShowingChanged method of your frame):

MyPanel1.Align := alNone;
MyPanel2.Align := alNone;
MyPanel1.Align := alBottom;
MyPanel2.Align := alBottom;

Restore in the order that you need - this seemed to sort out the order visually.

Brian Frost