将一个用户控件添加到另一个用户控件 [英] Adding one user control to another user control

查看:84
本文介绍了将一个用户控件添加到另一个用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

说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.


这篇关于将一个用户控件添加到另一个用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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