adding userControl to tabControl

本文关键字:tabControl to userControl adding | 更新日期: 2023-09-27 18:02:27

如何在c#中插入包含按钮,标签的userControl到TabControl页面?(代码是什么)

指出:

  • tabControl在userControl中,因为我需要这个tabControl用于其他表单。
代码:

public Courses()
{
  InitializeComponent();
  ucAction1.tpDelete // (userControl name,firts tabControl tabPage), i dont know how to move on from here?
}

adding userControl to tabControl

如果您只是想手动添加用户控件到选项卡:

tabPage1.Controls.Add(ucAction1);

更新:

我"认为"我理解你的问题。在用户控件中的tabcontrol中,将每个TabPage的Modifiers属性更改为Public。然后你可以访问它:

ucAction1.tabPage1.Controls.Add(new TextBox());
Public Sub addTabPage(ByVal Title As String)
    Dim TPage As New TabPage(Title)
    Dim UCInstance As New UControl()
    TPage.Controls.Add(UCInstance)
    TabControl1.TabPages.Add(TPage)
    UCInstance.Dock = DockStyle.Fill
End Sub

call UserControl1 on tapPage1

UserControl1 myUserControl = new UserControl1();
myUserControl.Dock = DockStyle.Fill;
tabPage1.Controls.Add(myUserControl);