简体   繁体   English

Windows窗体,对象出现在其他项目的前面?

[英]Windows form, objects appear infront of other items?

当我在我的表单中添加氪项时,它们会显示在其他项目的顶部,我怎么能这样做以便我可以在其他项目后面添加一些内容?

假设您正在使用Winform设计器,您可以右键单击一个控件并从上下文菜单中选择“Bring to Front”或“Send to Back”来更改控件的“z-order”。

The order of control appearing inside their parrent container is controlled by Z-Index. 出现在其容器内的控制顺序由Z-Index控制。

Right click control in the designer. 在设计器中右键单击控件。 Select "Bring ro front" from the context menu. 从上下文菜单中选择“Bring ro front”。

If you doing it programmtiacly. 如果你按程序进行。 All control in winforms environment have two methods : BringToFront() and SendToBack(). winforms环境中的所有控件都有两种方法:BringToFront()和SendToBack()。 You can call it to setup z-index of controls. 您可以调用它来设置控件的z-index。

If you want to specify Z-Index explicitly you may use this workaround: 如果要明确指定Z-Index,可以使用此解决方法:

public static class ControlExtension
{

    public static void SetControlZIndex(this Control ctrl, int z)
    {
       ctrl.Parent.Controls.SetChildIndex(ctrl, z);
    }
}

Usage: 用法:

button1.SetControlZIndex(10);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM