动态添加 usercontrol 到 tablelayout

例如我有这样的用户控件。我想将其动态添加到已知字段(tablelayout6)。我需要如何编辑此用户控件才能实现我的目标?我不知道如何参考我的表格布局。


public class Userblock : UserControl

{

    TextBox textName;

    Label labelName;

    cCheckedListBox listtablelayout6;


    public Userblock()

    {

        InitializeComponent();

    }


    public void InitializeComponent()

    {

        textName = new System.Windows.Forms.TextBox();

        labelName = new System.Windows.Forms.Label();

        labelName.Text = "Name:";

        listtablelayout6.Size =  new System.Drawing.Size(112, 100);

        Controls.AddRange(new System.Windows.Forms.Control[]

        {

            labelName,

            labelAddress,

            listtablelayout6

        });

    }

}


弑天下
浏览 85回答 1
1回答

泛舟湖上清波郎朗

这很简单..yourTableLayoutName.Controls.Add(new Button { Text = "I'm a Button" }); yourTableLayoutName.Controls.Add(new Label { Text = "I'm a Label" });您可以将控件的属性放在里面{ }
打开App,查看更多内容
随时随地看视频慕课网APP