在面板c#形式上"带来前面并带回来"是什么意思

use*_*477 0 c# forms

我正在使用c#拖放面板.面板不断出现和消失.我还需要面板盒功能的帮助,如"带到前面并带回来"我觉得这就是弄乱我的面板.它们是什么意思?

met*_*bed 7

Windows窗体设计器有一个名为的概念Z-order.当两个控件重叠时,Z顺序确定哪个控件将显示在顶部.

例如,假设你有两个控件叫textBox1pictureBox1Windows窗体上.以编程方式,this指的是Windows窗体本身,Controls是该窗体中控件的默认列表,textBox1并且是我们正在更改的实际控件.

选择菜单选项Bring to Front等同于调用控件的BringToFront()方法.这会将控件移动到Windows窗体的默认控件集合的开头.所以,如果你Bring To FronttextBox1,它会显示你上面的表格上的所有其他控件.编程方式,

// Bring the control in front of all other controls
this.textBox1.BringToFront();
Run Code Online (Sandbox Code Playgroud)

选择菜单选项Send to Back等同于调用控件的SendToBack()方法.这会将控件移动到Windows窗体的默认Controls集合的末尾.所以,如果你Send To BacktextBox1,它会显示你的窗体上的所有其他控件的后面.编程方式,

// Send the control behind all other controls
this.textBox1.SendToBack();
Run Code Online (Sandbox Code Playgroud)

您还可以通过编程方式更好地控制订购.在UI中无法做到这一点.所以:

// Put the control at the 2nd index in the Controls collection of this Form
this.Controls.SetChildIndex(this.textBox1, 2); 
Run Code Online (Sandbox Code Playgroud)

此页面在Windows窗体分层对象提供了一些更多详细信息.

Windows窗体控件页面:Z顺序和复制集合包含有关如何以编程方式控制Z顺序的示例.