winform程序中将控件置于最顶层或最底层的方法

时间:2014-02-18 16:02:49   收藏:0   阅读:389

有时,我们可能动态的添加控件,并准备将其置于对顶层或最底层。实现的方法有两个:

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

void SetChildIndex(Control child, int newIndex)

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

this.Controls.SetChildIndex(button1, 10);

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

另外一种方法是使用相应控件的使用其源代码如下:

button1.BringToFront();  //将控件放到所有控件最前端 button1.SendToBack();   //将控件放到所有控件最低端

原文:http://www.cnblogs.com/zfanlong1314/p/3554073.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!