Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS2010 Designer Z-Order

I'm trying to change the z-order for some docked panel in the VS2010 designer. However, everytime I save the designer, close it down and re-open it, the z-order has reverted back to how it was before I changed it.

I've tried using the document outline, and the SendToBack context menu but both behave in the same way. I've also noticed that in another solution where it does work, the .designer.cs file doesn't actually change (I assumed control adding order would dictate z-order).

Is there any other way I can do this? I really don't want to do this at runtime...

EDIT

this.mainPanel.BackColor = System.Drawing.SystemColors.Control;
this.mainPanel.Controls.Add(this.pnlRangeSelector);
this.mainPanel.Controls.Add(this.headerAndFooterRowCounts);

pnlRangeSelector has Dock.Top headerAndFooterRowCounts has Dock.Right

when this renders however, headerAndFooterRowCounts takes the entire right side of it's parent panel, while pnlRangeSelector takes the Left portion.

That suggests to me that the pnlRangeSelector isn't correctly at the back like it's supposed to be.

enter image description here

UPDATE

int i = 0;
String output = String.Empty;
foreach (var c in this.mainPanel.Controls)
{
    if (c == pnlRangeSelector) { output += "RangeSelector at : " + i.ToString() + "\r\n"; }
    else if (c == this.headerAndFooterRowCounts) { output += "HeaderAndFooter at : " + i.ToString() + "\r\n"; }
    i++;
}
MessageBox.Show(output);

Seems the order is always RangeSelector = 0, HeaderAndFooter = 1. Even if I call the following just prior to this:

this.mainPanel.Controls.SetChildIndex(this.pnlRangeSelector, 1);
this.mainPanel.Controls.SetChildIndex(this.headerAndFooterRowCounts, 0);
like image 617
Ian Avatar asked May 26 '11 11:05

Ian


2 Answers

The order in which the controls are added to the Controls collection of the parent determines the z-order. So the best way to solve this (AFAIK) is to make a backup of the designer file and then edit the order in which the controls are ADDED to the collection

Post the code if you need help.

like image 114
Emond Avatar answered Nov 15 '22 22:11

Emond


I had a similar problem and found the problem was in the Designer code. In my base form, caseHeader was docked to the top. Then, I added formInstructions and docked it to the top. Therefore, my base had formInstructions below the caseHeader. This is the desired appearance.

In derived forms, the appearance was reversed. I researched about docking, autosize, z-orders, etc. - all to no avail.

Finally, I found Designer was changing the child indices of various controls. This is what I did in the Designer code to fix the problem:

//this.Controls.SetChildIndex(this.caseHeader, 0);
like image 45
Jeff Matthews Avatar answered Nov 15 '22 21:11

Jeff Matthews