如何获取组件的实例名称? [英] How can I get the instance name of a component?

查看:62
本文介绍了如何获取组件的实例名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义组件,可以从ToolBox拖到一个

Windows窗体上(这意味着我无法修改它的构造函数来添加名称

参数)。 VS为其指定一个实例名称,但开发人员可以修改它的名称。该名称在属性窗口中显示为(name),

我想找到一种以编程方式访问该名称的方法,以便

实例的控制将能够确定它自己的名字。我有

控件的来源,我可以修改它,但我真的不想要

来添加一个新的名称。属性并让用户再次输入相同的名称

。用户已经输入了一次,我想找到一种方法来获得它。
得到它。有没有人有任何想法?

解决方案

这不仅仅是Name属性的值,还是我错过了

什么东西?


没有名称属性,这就是为什么属性检查员显示

paenthesis around它:(名称)。似乎组件和

IComponent都没有定义Name属性。如果我检查这个.ToString()它

显示类的名称,而不是实例的名称。我是

猜测实际的实例名称可能是容器问题,而不是

与组件实例一起存储的东西?


抱歉。我在考虑控制

http://msdn2.microsoft.com/en-us/lib...es(VS.80).aspx


,它有一个Name属性。


I have a custom component that can be dragged from the ToolBox onto a
Windows Form (which means I can''t modify it''s constructor to add a name
parameter). VS assigns it an instance name, but the developer can
modify it''s name. The name shows up in the property window as "(name)",
I want to find a way to access that name programatically, so that
instance of the control wil be able to determine it''s own name. I have
the source for the control and I can modify it, but I really don''t want
to add a new "name" property and make the user enter the same name
again. The user already entered it once, and I want to find a way to
get that. Does anyone have any ideas?

解决方案

Isn''t this just the value of the Name property, or am I missing
something?


There is no name property, which is why the property inspector shows
paraenthesis around it: "(name)". It seems that neither Component nor
IComponent define a Name property. If I examine this.ToString() it
shows me the name of the class, and not the name of the instance. I''m
guessing the actual instance name may be a container matter, and not
something that is stored with the component instance?


Sorry. I was thinking of Control

http://msdn2.microsoft.com/en-us/lib...es(VS.80).aspx

which does have a Name property.


这篇关于如何获取组件的实例名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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