我正在尝试更改 VS2010 设计器中某些停靠面板的 z 顺序。然而,每次我保存设计器、关闭它并重新打开它时,z 顺序都会恢复到我更改它之前的状态。
我试过使用文档大纲和 SendToBack 上下文菜单,但两者的行为方式相同。我还注意到,在它确实有效的另一个解决方案中,.designer.cs 文件实际上并没有改变(我假设控件添加顺序会决定 z 顺序)。
有没有其他方法可以做到这一点?我真的不想在运行时这样做......
编辑
this.mainPanel.BackColor = System.Drawing.SystemColors.Control;
this.mainPanel.Controls.Add(this.pnlRangeSelector);
this.mainPanel.Controls.Add(this.headerAndFooterRowCounts);
pnlRangeSelector 有 Dock.Top headerAndFooterRowCounts 有 Dock.Right
然而,当它呈现时,headerAndFooterRowCounts 占据其父面板的整个右侧,而 pnlRangeSelector 占据左侧部分。
这表明 pnlRangeSelector 没有像它应该的那样正确地位于后面。
更新
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);
似乎顺序总是 RangeSelector = 0,HeaderAndFooter = 1。即使我在此之前调用了以下命令:
this.mainPanel.Controls.SetChildIndex(this.pnlRangeSelector, 1);
this.mainPanel.Controls.SetChildIndex(this.headerAndFooterRowCounts, 0);
最佳答案
控件添加到父控件集合的顺序决定了 z 顺序。所以解决这个问题的最好方法(AFAIK)是备份设计器文件,然后编辑控件添加到集合
的顺序如果您需要帮助,请发布代码。
关于c# - VS2010 设计器 Z 顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6137514/