为了账号安全,请及时绑定邮箱和手机立即绑定

动态添加 usercontrol 到 tablelayout

动态添加 usercontrol 到 tablelayout

C#
弑天下 2022-11-22 16:38:02
例如我有这样的用户控件。我想将其动态添加到已知字段(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        });    }}
查看完整描述

1 回答

?
泛舟湖上清波郎朗

TA贡献1818条经验 获得超3个赞

这很简单..

yourTableLayoutName.Controls.Add(new Button { Text = "I'm a Button" });
yourTableLayoutName.Controls.Add(new Label { Text = "I'm a Label" });

您可以将控件的属性放在里面{ }


查看完整回答
反对 回复 2022-11-22
  • 1 回答
  • 0 关注
  • 82 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信