如何将用户控件添加到面板 [英] How to add user control to panel
本文介绍了如何将用户控件添加到面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的项目中创建了多个用户控件,我需要做的是能够在面板控件上在它们之间切换.
I have created multiple user controls in my project and what I need to do is to be able to switch between them on a panel control.
例如,如果用户单击 button1,则在删除其上的所有控件等后,userControl1 将被添加到面板中.
for example, if the user click button1, userControl1 will be added to panel after removing every control on it and so on.
我有这个代码:
panel1.Controls.Add(MyProject.Modules.Masters);
但它不起作用.
我该怎么做?
推荐答案
您必须实例化您的控件.您必须确保正确设置尺寸,或者使其具有适当的装卸区.
You have to instantiate your controls. You will have to make sure the size is set appropriately, or for it to have an appropriate dockfill.
var myControl = new MyProject.Modules.Masters();
panel1.Controls.Add(myControl);
这篇关于如何将用户控件添加到面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文