Windows form, objects appear infront of other items?

陌路散爱 提交于 2019-12-10 14:10:33

问题


When I add krypton items to my form, they appear over the top of the others, how can I make it so that I can put something behind the other items?


回答1:


Assuming you're using the Winform designer, you can right click a control and select 'Bring to Front' or 'Send to Back' from the context menu to change the control's 'z-order.'




回答2:


The order of control appearing inside their parrent container is controlled by Z-Index.

Right click control in the designer. Select "Bring ro front" from the context menu.

If you doing it programmtiacly. All control in winforms environment have two methods : BringToFront() and SendToBack(). You can call it to setup z-index of controls.

If you want to specify Z-Index explicitly you may use this workaround:

public static class ControlExtension
{

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

Usage:

button1.SetControlZIndex(10);


来源:https://stackoverflow.com/questions/6049927/windows-form-objects-appear-infront-of-other-items

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!