如何将UserControl显示到表单中

Spo*_*ina 2 c# winforms

我创建了一个UserControl,当我点击某个按钮将这个UserControl显示到我的表单中时我想要.

有没有办法做到这一点?

Ada*_*her 10

您可以将用户控件动态添加到窗体控件集合.

例如,在按钮单击事件处理程序中:

MyUserControl uc = new MyUserControl();
uc.Dock = DockStyle.Fill;
this.Controls.Add(uc);
Run Code Online (Sandbox Code Playgroud)