如何在面板上的预览顶部停靠控件下方插入顶部停靠控件 [英] How to insert top docked controls below previewsly top docked controls on a panel

查看:28
本文介绍了如何在面板上的预览顶部停靠控件下方插入顶部停靠控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 panel.controls.add 向面板添加控件.但是......它们插入在它的最顶部.

I use panel.controls.add to add controls to the panel. But... they insert at the very top of it.

我尝试了BringToFront 和SendToBack 方法,但似乎不起作用.

I tried the BringToFront and SendToBack methods, but does'nt seem to be working.

有什么想法吗?谢谢

我想要的是,它们停靠在容器的顶部,但是如果那里还有另一个停靠的控件,则新控件会显示在该控件下方...

what i want, is that they dock at the top of the container, but if there is another docked control there, the new one is displayed below that one...

推荐答案

停靠顺序基于 Controls 集合中控件的索引.最后一个在上面.这就是为什么您添加的控件位于顶部并将现有的停靠控件向下推.使用 SetChildIndex() 方法将控件移动到索引 0:

The docking order is based on the index of the control in the Controls collection. The last one goes on top. Which is why your added control goes on top and pushes an existing docked control down. Use the SetChildIndex() method to move the control to index 0:

        var btn = new Button();
        btn.Dock = DockStyle.Top;
        panel1.Controls.Add(btn);
        panel1.Controls.SetChildIndex(btn, 0);

这篇关于如何在面板上的预览顶部停靠控件下方插入顶部停靠控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆