将一个用户控件添加到另一个用户控件

将一个用户控件添加到另一个用户控件

问题描述:

如何将一个用户控件添加到另一个用户控件?

说UserControl1和UserControl2。

我想将UserControl2添加到UserControl1。

我该怎么办?

How to add one user control to another user control??
Say UserControl1 and UserControl2.
I want to add the UserControl2 to UserControl1.
How can I do It??

UserControl1.Controls.Add(UserControl2) - 用实例替换类型名



如果这些是UI控件,你应该能够通过将它们拖到设计器表面上来将它们添加到另一个。



这应该可以做到

UserControl1.Controls.Add(UserControl2) - replace typenames with real instances

If these are UI controls you should be able to add one to the other by dragging them onto designer surface.

This should do the trick
UserControl2 u2 = new UserControl2
UserControl1 u1 = new Usercontrol1

u1.Controls.Add(u2)





它只是就像添加按钮或文本框一样。



It is just the same as if you're adding a button or textbox.