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.com
"John" <jo********@hotmail.com> wrote in message
news:d8**************************@posting.google.c om...
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.Writeline(tbbMyButton.Name); // Doesn't work, no Name
property
}
}
Maybe something with reflection?
Thanks!!!
John