控件遮盖问题

来源:互联网 发布:薇诺娜淘宝旗舰店 编辑:程序博客网 时间:2024/04/29 18:53

1.通过在From1.Designer.cs文件中修改this.Controls.Add(控件)的顺序,可修改控件的层次,越先add的就越在顶层


2.还有一种方法是在WinForm窗体中使用Controls控件集的SetChildIndex方法,该方法将子控件设定为指定的索引值,其方法原型如下:

void SetChildIndex(Control child, int newIndex)

假设窗体中有一个按钮Button控件,名为button1,如果将其的索引设置为10,源代码如下:

this.Controls.SetChildIndex(button1, 10);

索引越大,控件位置越靠上。


3.可通过代码使控件置于顶层或底层:

button.BringToFront();

button.SendToBack();