通过字符串值加载UserControl [英] Load an UserControl by string value

查看:82
本文介绍了通过字符串值加载UserControl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一些名为a1,a2,b1,b2 ...的UserControl,并且我想根据两个变量的值加载其中一个.例如,var1 = a,var2 = 1将加载名为a1的UserControl.
有没有办法做到这一点?还有其他方法吗?
开关不可行,因为会有200个不同的UserControl.
预先谢谢您.

Hi,
I have some UserControls named a1, a2, b1, b2... and I want to load one of them depending of the value of two variables. For example, var1 = a, var2 = 1 will load the UserControl named a1.
Is there a way of doing this? Some other approach?
A switch is not viable, because there will be like 200 different UserControls.
Thank you in advance.

推荐答案

您可以使用 ^ ]用于加载控件的方法.通过组合变量来生成用户控件的名称.
You can use the LoadControl[^] method for loading the controls. Generate the name of user controls by combining the variables.


这篇关于通过字符串值加载UserControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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