控制集合 [英] Control collection

查看:55
本文介绍了控制集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我可以通过它的索引访问表单上的特定控件,例如me.Controls.Item(0).Name


如何通过名称访问控件,例如me.Controls.Item(QUOT; Label1的")名称。可能吗?


谢谢


Ian

解决方案

Ian,

我不认为这是直接可能的,但是,我可能在这里被证明是错的。问题是IndexOf和Contains方法都需要将控件传递给它们。


但是,如果你想这样做,你可以创建一个列表,其中索引号是控件集合中的索引,这样你就可以通过名字来引用它。


我很想知道你是否找到了其他方法!


问候 - OHM


" Ian" < IH **** @ hotmail.com>在留言新闻中写道:OF ************* @ tk2msftngp13.phx.gbl ...




我可以通过它的索引访问表单上的特定控件,例如me.Controls.Item(0).Name


如何通过名称访问控件,例如me.Controls.Item(QUOT; Label1的")名称。可能吗?


谢谢


Ian


* "伊恩" < IH **** @ hotmail.com> scripsit:

我可以通过它的索引访问表单上的特定控件,例如me.Controls.Item(0).Name

如何通过名称访问控件,例如me.Controls.Item(" Label1")。名称。*是否可能?




这是不可能的,但你可以将所有控件添加到a ''Hashtable''

((name = key,value = reference)对)然后通过哈希表访问控件




-

Herfried K. Wagner [MVP]

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


"伊恩" < IH **** @ hotmail.com> schrieb


我可以通过它的索引访问表单上的特定控件,例如
me.Controls.Item(0).Name
我如何通过名称访问控件,例如
me.Controls.Item(" Label1")。名称。有可能吗?



Me.Label1.Text ="它'是我'

-

Armin < > http://www.plig.net/nnq /nquote.html
http:// www。 netmeister.org/news/learn2quote.html


Hi

I can access a particular control on a form by it''s index e.g. me.Controls.Item(0).Name

How would I access the control by name e.g. me.Controls.Item("Label1").Name. Is it possible?

Thanks

Ian

解决方案

Ian,
I Dont think this is directly possible, however, I might be proved wrong here. The problem is that the IndexOf and Contains methods both require a control to be passed to them.

However, if you wanted to do this, you could create a list, where the index number was the index in the controls collection, this way you could refer to it by name.

I would be interested to know if you do find a way other than that !

Regards - OHM


"Ian" <ih****@hotmail.com> wrote in message news:OF*************@tk2msftngp13.phx.gbl...
Hi

I can access a particular control on a form by it''s index e.g. me.Controls.Item(0).Name

How would I access the control by name e.g. me.Controls.Item("Label1").Name. Is it possible?

Thanks

Ian


* "Ian" <ih****@hotmail.com> scripsit:

I can access a particular control on a form by it''s index e.g. me.Controls.Item(0).Name

How would I access the control by name e.g. me.Controls.Item("Label1").Name.* Is it possible?



That''s not possible, but you can add all controls to a ''Hashtable''
((name = key, value = reference) pairs) and then access the controls
through the hashtable.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>


"Ian" <ih****@hotmail.com> schrieb


I can access a particular control on a form by it''s index e.g.
me.Controls.Item(0).Name

How would I access the control by name e.g.
me.Controls.Item("Label1").Name. Is it possible?


Me.Label1.Text = "it''s me"
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


这篇关于控制集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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