简体   繁体   English

如何在TableLayoutpanel中的特定位置上添加用户控件

[英]How to Add Usercontrols on a specific position in a TableLayoutpanel

Team. 球队。

I have a Problem with my Tablelayoutpanel. 我的Tablelayoutpanel有问题。 The Tablelayoutpanel is located in the Main-Form and filled with 5 Usercontrols (5 equal Controls, filled with other texts). Tablelayoutpanel位于主窗体中,并用5个用户控件填充(5个相等的控件,并填充其他文本)。 Every Usercontrol contains a button. 每个用户控件都包含一个按钮。 If I click on that button in the UC, 10 other Usercontrols should be added AFTER the clicked Usercontrol. 如果单击UC中的该按钮,则应在单击的Usercontrol之后添加其他10个Usercontrol。

My Code so far (In the Button-Click Method): 到目前为止,我的代码(在“单击按钮”方法中):

private void bt_Öffnen_Click(object sender, EventArgs e)
    {
        var ziele = getZielStatement();

        foreach (var z in ziele.Where(z => z.Hauptziele.PerspektivenID == gl_PerspektiveID)) // Für jedes Ziel in der jeweiligen Perspektive
        {             
            Uc_Ziele uc_ziel = new Uc_Ziele();
            uc_ziel.gl_Unterziel = z;
            this.Parent.Controls.Add(uc_ziel);               
        }
    }

The problem is, that the Controls are added at the end of TableLayoutpanel. 问题是,控件被添加到TableLayoutpanel的末尾。 They should be added after the clicked Usercontrol. 它们应该在单击用户控件之后添加。

I cant do it without help. 我不能没有帮助。 Hope you get what i want. 希望你能得到我想要的。

Greets, Daniel 问候,丹尼尔

After you've added the control use the SetChildIndex method to move it to its correct position. 添加控件后,使用SetChildIndex方法将其移至正确位置。

Check out this post for further info 查看此帖子以获取更多信息

How to add rows into middle of a TableLayoutPanel 如何在TableLayoutPanel的中间添加行

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

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