Reputation: 8753
I start out with a control that has three child controls, docked to the top, bottom, and fill. Two skinny bands at the top and a big rectangle in the middle.
Later on, programatically I want to add a slim band to the left.
But when I do it, I get the left band overlapping with the big middle one.
How should I be readjusting these controls?
Upvotes: 1
Views: 163
Reputation: 2594
Once you have instanciated the new control, you can give it a specific index to be located.
The lower the index, the higher priority it will have.
Example code*:
var control = new Button();
control.Dock = DockStyle.Left;
this.Controls.Add(control);
this.Controls.SetChildIndex(control, 0);
(I just used a button because it was easy to see inside a form.)
However doing this dynamically may not be the best thing. I would recommend creating the control on the left the entire time, then making it visible when applicable. Doing this method, you get the Designer to help place the control in the right spot, rather than generating the right spot.
If you so choose to use the enable/disable visibility at runtime, you may have to tweak the Document Outline. It's located at View
-> Other Windows
-> Document Outline
when in the Designer view. (It's a dockable window like the toolbox.)
Upvotes: 2
Reputation: 544
You need a control that holds the slim band and a control located on the right. Place the two skinny bands and one rectangle in the right-hand control.
Upvotes: 0