如何将 UserControl 显示到表单中 [英] How can I Display UserControl into a form

查看:35
本文介绍了如何将 UserControl 显示到表单中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have created a UserControl and I want when I click on some button to display this UserControl into my form.

有没有办法做到这一点?

Is there any way to do that ?

推荐答案

您可以将用户控件动态添加到表单控件集合中.

You can dynamically add the user control to the forms Controls collection.

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

For example, in the button click event handler:

MyUserControl uc = new MyUserControl();
uc.Dock = DockStyle.Fill;
this.Controls.Add(uc);

这篇关于如何将 UserControl 显示到表单中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆