473,587 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to display the name of an object instance?

Hi,

I have a ToolbarButton and I want to print out the instance name. This
is easy to do with objects that inherit from Control because there is
a .Name property. However, with other objects like ToolbarButton I
don't see how to do this.

Advice? Ideas? THANKS!

ToolbarButton tbbMyButton;

public static void ShowName(object o)
{
if ( o is ToolbarButton )
{
Console.Writeli ne(tbbMyButton. Name); // Doesn't work, no Name
property
}
}

Maybe something with reflection?

Thanks!!!

John
Nov 16 '05 #1
3 1577
John <jo********@hot mail.com> wrote:
I have a ToolbarButton and I want to print out the instance name. This
is easy to do with objects that inherit from Control because there is
a .Name property. However, with other objects like ToolbarButton I
don't see how to do this.

Advice? Ideas? THANKS!

ToolbarButton tbbMyButton;

public static void ShowName(object o)
{
if ( o is ToolbarButton )
{
Console.Writeli ne(tbbMyButton. Name); // Doesn't work, no Name
property
}
}

Maybe something with reflection?


Objects don't *have* names usually. What do you actually want to see?

Don't forget that there's a big difference between an object and a
variable containing a reference to an object. A variable has a name,
but there could be lots of variables with references to a specific
object - or none!

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
John,

The Name property of a Control instance isn't really applicable. Say
you had a button, which was named mobjButton. What happens when you do
this?

// Assign the button locally.
Button pobjButton = mobjButton;

What should the name be then? mobjButton or pobjButton? Both are
legitimate names for the object instance.

If you want to get the name of the field for an object instance, then
you can call the GetFields method on the Type class. Since all instances
will have the same field names, you can just use these.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"John" <jo********@hot mail.com> wrote in message
news:d8******** *************** ***@posting.goo gle.com...
Hi,

I have a ToolbarButton and I want to print out the instance name. This
is easy to do with objects that inherit from Control because there is
a .Name property. However, with other objects like ToolbarButton I
don't see how to do this.

Advice? Ideas? THANKS!

ToolbarButton tbbMyButton;

public static void ShowName(object o)
{
if ( o is ToolbarButton )
{
Console.Writeli ne(tbbMyButton. Name); // Doesn't work, no Name
property
}
}

Maybe something with reflection?

Thanks!!!

John

Nov 16 '05 #3
That helps a lot. Thank you!

I was so focused on the reference to the instance that I forgot to
consider the FieldInfo that I get from the type. FieldInfo has exactly
what I need.

THANKS!!!
John

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in message news:<#r******* *******@TK2MSFT NGP12.phx.gbl>. ..
John,

The Name property of a Control instance isn't really applicable. Say
you had a button, which was named mobjButton. What happens when you do
this?

// Assign the button locally.
Button pobjButton = mobjButton;

What should the name be then? mobjButton or pobjButton? Both are
legitimate names for the object instance.

If you want to get the name of the field for an object instance, then
you can call the GetFields method on the Type class. Since all instances
will have the same field names, you can just use these.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"John" <jo********@hot mail.com> wrote in message
news:d8******** *************** ***@posting.goo gle.com...
Hi,

I have a ToolbarButton and I want to print out the instance name. This
is easy to do with objects that inherit from Control because there is
a .Name property. However, with other objects like ToolbarButton I
don't see how to do this.

Advice? Ideas? THANKS!

ToolbarButton tbbMyButton;

public static void ShowName(object o)
{
if ( o is ToolbarButton )
{
Console.Writeli ne(tbbMyButton. Name); // Doesn't work, no Name
property
}
}

Maybe something with reflection?

Thanks!!!

John

Nov 16 '05 #4

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

Similar topics

1
2668
by: FrankBooth | last post by:
Hello, I have a list of names, and when I click ona name I want the extar info to show and then I want to clcik and hide it again. I have the following HTML which works perfectly if I use one construct, but if I use more that one it issues an object error which states that: ExpCollTxt_ctrl_ex.style is not an object. So the followin...
6
22505
by: Martin | last post by:
I'd like to be able to get the name of an object instance from within a call to a method of that same object. Is this at all possible? The example below works by passing in the name of the object instance (in this case 'myDog'). Of course it would be better if I could somehow know from within write() that the name of the object instance was...
2
19843
by: Mamatha | last post by:
Hi I want to add an icon to the textbox's text. I don't know how to display icon in textbox in VB.NET. If any one knows please let me know. Thanks in advance. Mamatha
3
61131
by: Nofi | last post by:
Hello, I'm trying to fill my combobox per code, not with a DataSet because I want to have an empty row in it and this wasn't possible when working with a DataSet. The fill works fine, but when I set the value and display member I get false values. string sConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Dokumente und...
1
4519
by: rbinington | last post by:
Hi, I am trying to write a DNN module that has the ability to insert articles into an article repository. I want the users to be able to move pages around and enter text into the FCKEditor. I want only one instance of the FCKEditor on the screen at one time so I make tabs that the user can click and I store the values in variables behind the...
6
3872
sammyboy78
by: sammyboy78 | last post by:
I'm trying to display my array of objects in a GUI. How do I get JLabel to refer to the data in my objects? I've read my textbook and some tutorials online I just cannot get this. Plus all the examples I've seen are creating the information that will be displayed from scratch, while I have to use my previously created classes and add a GUI to it....
0
2301
parshupooja
by: parshupooja | last post by:
Contact Reply 1 point Member propoo Joined on 08-31-2007, 10:32 PM Posts 3 Hey all ,
0
1046
by: AlDave | last post by:
What I'm trying display is after the user chooses the product (1st category) from a dropdown, then the dataview will display; The category any reports under that subcategory any reports under that
1
1591
by: =?Utf-8?B?Q2hhcmxlcw==?= | last post by:
I'm running VS2008 & attempting to solve a problem I've encountered while developing some software for our business. Here's the basic idea...I've created a class that represents a file (with members such as file name, file location, and a string containing the files data). Each file object also contains an ArrayList of another custom object...
0
7923
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7852
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7974
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5719
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3845
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2364
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 we have to send another system
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.