473,509 Members | 3,032 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I get the instance name of a component?

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?

Feb 28 '06 #1
12 12141
Isn't this just the value of the Name property, or am I missing
something?

Feb 28 '06 #2
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?

Feb 28 '06 #3
Sorry. I was thinking of Control

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

which does have a Name property.

Feb 28 '06 #4
Hello,

This post doesn't appear to have a suggested solution. I would like to
accomplish the same.

Does anyone have any suggestions?
May 4 '06 #5
HairlipDog58,

You aren't really going to be able to find that out. If by instance
name, you mean the name of the variable, since multiple variables can
reference the same object, you could end up with more than one.

What are you trying to accomplish by doing this?

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"HairlipDog58" <Ha********@nospam.nospam> wrote in message
news:E0**********************************@microsof t.com...
Hello,

This post doesn't appear to have a suggested solution. I would like to
accomplish the same.

Does anyone have any suggestions?

May 4 '06 #6
Hi Nicholas,

Components can be sited on a form or created programmatically. When sited on
a form, in design mode, the component can be configured through the VS.NET
Properties Grid. In the property grid for the component, there is a property
called (Name), which is the component's programmatic name. This is the
property that I would like access to.

The designer automatically assigns a name to the component when it creates
it. This name shows up in the property grid as '(Name)'. Since '(Name)' is
not accessible programmatically (that I know of), I've implemented a property
called Label to identify the component at runtime.

When the component is created, I would like the Label property to default to
the same value as the (Name) property.

"Nicholas Paldino [.NET/C# MVP]" wrote:
HairlipDog58,

You aren't really going to be able to find that out. If by instance
name, you mean the name of the variable, since multiple variables can
reference the same object, you could end up with more than one.

What are you trying to accomplish by doing this?

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"HairlipDog58" <Ha********@nospam.nospam> wrote in message
news:E0**********************************@microsof t.com...
Hello,

This post doesn't appear to have a suggested solution. I would like to
accomplish the same.

Does anyone have any suggestions?


May 4 '06 #7
That property is not a property of the actual component, but the name
that the property designer uses for the name in the class.

If you want this, you could enumerate through the fields of the class
that it is contained in (using Reflection), and then check the type to see
if it has a Label property. If it does, then you can set it.

You might want to change your Label property to Text, as it seems more
in line with established convention (or override the Text property if there
is one).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"HairlipDog58" <Ha********@nospam.nospam> wrote in message
news:A4**********************************@microsof t.com...
Hi Nicholas,

Components can be sited on a form or created programmatically. When sited
on
a form, in design mode, the component can be configured through the VS.NET
Properties Grid. In the property grid for the component, there is a
property
called (Name), which is the component's programmatic name. This is the
property that I would like access to.

The designer automatically assigns a name to the component when it creates
it. This name shows up in the property grid as '(Name)'. Since '(Name)' is
not accessible programmatically (that I know of), I've implemented a
property
called Label to identify the component at runtime.

When the component is created, I would like the Label property to default
to
the same value as the (Name) property.

"Nicholas Paldino [.NET/C# MVP]" wrote:
HairlipDog58,

You aren't really going to be able to find that out. If by instance
name, you mean the name of the variable, since multiple variables can
reference the same object, you could end up with more than one.

What are you trying to accomplish by doing this?

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"HairlipDog58" <Ha********@nospam.nospam> wrote in message
news:E0**********************************@microsof t.com...
> Hello,
>
> This post doesn't appear to have a suggested solution. I would like to
> accomplish the same.
>
> Does anyone have any suggestions?
>
>


May 4 '06 #8
Nicholas,

I already have access to the Label property, it is a property of my
component. When the component instance is created, I want to assign the Label
property a default value that is the same value as 'the name that the
property designer uses for the name in the class'.

"Nicholas Paldino [.NET/C# MVP]" wrote:
That property is not a property of the actual component, but the name
that the property designer uses for the name in the class.

If you want this, you could enumerate through the fields of the class
that it is contained in (using Reflection), and then check the type to see
if it has a Label property. If it does, then you can set it.

You might want to change your Label property to Text, as it seems more
in line with established convention (or override the Text property if there
is one).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"HairlipDog58" <Ha********@nospam.nospam> wrote in message
news:A4**********************************@microsof t.com...
Hi Nicholas,

Components can be sited on a form or created programmatically. When sited
on
a form, in design mode, the component can be configured through the VS.NET
Properties Grid. In the property grid for the component, there is a
property
called (Name), which is the component's programmatic name. This is the
property that I would like access to.

The designer automatically assigns a name to the component when it creates
it. This name shows up in the property grid as '(Name)'. Since '(Name)' is
not accessible programmatically (that I know of), I've implemented a
property
called Label to identify the component at runtime.

When the component is created, I would like the Label property to default
to
the same value as the (Name) property.

"Nicholas Paldino [.NET/C# MVP]" wrote:
HairlipDog58,

You aren't really going to be able to find that out. If by instance
name, you mean the name of the variable, since multiple variables can
reference the same object, you could end up with more than one.

What are you trying to accomplish by doing this?

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"HairlipDog58" <Ha********@nospam.nospam> wrote in message
news:E0**********************************@microsof t.com...
> Hello,
>
> This post doesn't appear to have a suggested solution. I would like to
> accomplish the same.
>
> Does anyone have any suggestions?
>
>


May 4 '06 #9
I ended up storing the name in the Tag property. Not ideal, but it was
good enough for me.

I noticed that VS 2005 has fixed this matter. They now seem to be
storing real names with the control instances. At least they do for
many of them - I'm not sure if this applies to all of them. Look in the
code the form designer creates for you - that's where they set it now.

Eric

May 4 '06 #10
Not sure if we're talking about the same thing here.

I'm interested in getting the name assigned by the designer to the component
instance. How did you get the component's name to store in the Tag property?

"Eric" wrote:
I ended up storing the name in the Tag property. Not ideal, but it was
good enough for me.

I noticed that VS 2005 has fixed this matter. They now seem to be
storing real names with the control instances. At least they do for
many of them - I'm not sure if this applies to all of them. Look in the
code the form designer creates for you - that's where they set it now.

Eric

May 4 '06 #11
The VS 2005 designer populates the Name property, so it should be easy
with that.

The Tag property just holds any object you want to associate with
controls. You can put anything there, and it follows the instance.

In VS 2003, you drop the control down (I was using menu items), and
then you see the name in the Property window. Scroll down to find the
Tag property in the Property window and type in the name there (or copy
and paste). Once you do this, the name will be available in the
instance by reading the Tag property. Since Tag holds an object you'll
have to cast it to a string to read it.

May 5 '06 #12
I'm pretty sure we're not talking about the same thing here.

The original posting was 'How can I get the instance name of a component?',
which is what I am interested in.

I think you are referring to the Control class, which does have an
accessible Name property, as oppposed to the Component class which does not.
May 5 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1782
by: Yasutaka Ito | last post by:
Hi, As you know, all the non-ui components (like Timer control, etc.) that sit on the form are contained in its private variable 'components'. How can I enumerate such components from any form...
2
5549
by: Mike | last post by:
Greetings, Having a major problem here. running version 8.2 on win2003 server. The problem I am having is backing up a database seems to get to the last part of the backup and then fails. This...
1
1353
by: Henrik Dahl | last post by:
Hello! I have a typical GoF Composite Pattern. It means an abstract Component class and two concrete classes Primitive and Composite. In my DoDragDrop() method call I'll therefore pass an...
11
2163
by: Özden Irmak | last post by:
Hello, In my VB.Net application I create a new instance of my form like : NewForm = new MyNewForm() But with this line, this new form is automatically shown. I want it to be hidden at the...
1
6467
by: vijay.db | last post by:
Hi Team, Very serious problem with my DB2 V8.1 Fixpack 6 running in AIX 5.1 machine. Every one hour my DB2 instance processes are killed and it's going down. Several trap files are generated in...
1
8332
by: Don | last post by:
I'm getting the following exception displayed in the task list at design time for my project: "Code generation for property 'Controls' failed. Error was: 'Object reference not set to an...
0
1575
by: ssnsridhar | last post by:
Hi, I ve saw a sample instance provider and have done a service which wil just display wat i have entered in ma service code.. Now i want to Enumerate, Create, Get, Modify operations. Can anyone...
6
5644
by: raylopez99 | last post by:
Anybody use Strong Name Signing? I think this is used by default for Resource files, which is one reason perhaps I can't get my resource files to work (somehow the public key is messed up, perhaps...
0
2630
tlhintoq
by: tlhintoq | last post by:
My project involves reading magstripe cards, capturing an ID number, then spinning off to do some other things including taking a photograph. 99% of this is done and good. All early phases of work...
0
7412
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5652
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3216
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.