如何在运行时添加未知控件 [英] How add unknown control at runtime

查看:69
本文介绍了如何在运行时添加未知控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




如何在我的form1中在运行时添加一个新的未知控件?


Thaks。

解决方案

我想创建一个控件,我只将你的类型变成一个字符串。

示例:

c = " System.Windows.Forms.TextBox"


我该怎么办?

"JoséTeixeiraJunior" < TE ************* @ stinfo.com.br> escreveu na mensagem

新闻:O0 ************** @ TK2MSFTNGP11.phx.gbl ...


如何在我的form1中在运行时添加一个新的未知控件?

Thaks。



< blockquote>嗨José,Morpheu,

何塞,我不知道你的控制是多么未知,但这可能会回答你的

查询。如果没有,请告诉我更多关于你想做什么的事情。


Morpheu,以下将创建一个名为按钮的控件。

Public Function MakeControl(sTypeName As String)As Control

Dim sFormTypeName As String = GetType(Form).AssemblyQualifiedName

sTypeName = sFormTypeName.Replace("表单,",sTypeName&",")

Dim oType As Type = Type.GetType(sTypeName)

返回DirectCast(Activator.CreateInstance(oType) ,控制)

结束功能


这是在一周前回答类似查询时给出的。如需解释

的工作方式,请参阅
http:/ /tinyurl.com/r393


问候,

Fergus


*" ;JoséTeixeiraJunior < TE ************* @ stinfo.com.br> scripsit:

如何在我的form1中在运行时添加一个新的未知控件?




请不要多重插件。


-

Herfried K. Wagner

MVP·VB Classic,VB.NET

< http ://www.mvps.org/dotnet>


Hi,

How i can add one new unknown control at runtime in my form1?

Thaks.

解决方案

I want create a control where i only have your type into a string.
Example:
c = "System.Windows.Forms.TextBox"

How can i do?
"José Teixeira Junior" <te*************@stinfo.com.br> escreveu na mensagem
news:O0**************@TK2MSFTNGP11.phx.gbl...

Hi,

How i can add one new unknown control at runtime in my form1?

Thaks.



Hi José, Morpheu,

Jose, I don''t know how ''unknown'' your control is but this may answer your
query. If not, tell me more about what you want to do.

Morpheu, the following will create a Control given a name such a "Button".

Public Function MakeControl (sTypeName As String) As Control
Dim sFormTypeName As String = GetType (Form).AssemblyQualifiedName
sTypeName = sFormTypeName.Replace ("Form,", sTypeName & ",")
Dim oType As Type = Type.GetType (sTypeName)
Return DirectCast (Activator.CreateInstance (oType), Control)
End Function

This was given in answer to a similar query a week ago. For an explanation
of how it works, see
http://tinyurl.com/r393

Regards,
Fergus


* "José Teixeira Junior" <te*************@stinfo.com.br> scripsit:

How i can add one new unknown control at runtime in my form1?



Please don''t multipost.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>


这篇关于如何在运行时添加未知控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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