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

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

void SetChildIndex(Control child, int newIndex)

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

this.Controls.SetChildIndex(button1, 10);

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

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

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

相关文章:

  • 2022-12-23
  • 2022-02-08
  • 2022-02-08
  • 2021-12-19
  • 2022-01-20
  • 2022-12-23
  • 2021-11-04
  • 2021-06-20
猜你喜欢
  • 2022-12-23
  • 2021-10-11
  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
相关资源
相似解决方案