简体   繁体   English

如何在另一个的TOP上添加自定义控件

[英]How to add a custom control on TOP of another one

I'm using a winForm. 我正在使用winForm。 I have 2 custom controls that I want to add dynamically. 我有2个动态添加的自定义控件。 The first one is added at the opening of the form. 第一个是在表格的开头添加的。 The second one is added when the user clicks a button. 当用户单击按钮时添加第二个。 Nothing magic here. 这里没什么了不起的。 The problem is that when I instanciate and add the second control, instead of appearing on top of the other one, it appears under. 问题是,当我实例化并添加第二个控件时,它不会显示在另一个控件之上,而是显示在第二个控件之上。

There must be a way to add the control in a way that will make it fully visible (on top of the rest). 必须有一种方法来添加控件,使其完全可见(在其余的顶部)。 Here is how I create the second control (same way as the first control). 这是我如何创建第二个控件(与第一个控件相同)。 I tried using show/hide methods, but this won't change the stack order. 我尝试使用show / hide方法,但这不会改变堆栈顺序。

    private void lbRappel_Click(object sender, EventArgs e)
    {
        NoteCallBack noteCallBack = new NoteCallBack("test");
        this.Controls.Add(noteCallBack);
        noteCallBack.Location = new Point(200, 250);
    }

Thank you very much in advance for your help. 非常感谢您的帮助。

Mathieu 马蒂厄

You could try the BringToFront control function: 您可以尝试BringToFront控制功能:

private void lbRappel_Click(object sender, EventArgs e)
{
    NoteCallBack noteCallBack = new NoteCallBack("test");
    this.Controls.Add(noteCallBack);
    noteCallBack.Location = new Point(200, 250);
    noteCallBack.BringToFront();
}

您可以在设计时使用所需的z顺序创建它们,然后只在运行时使它们可见吗?

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

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