Obtaining object name at design time

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello all

I am working on a serialization formatter to store and load control properties at both design time and run time

I am having a problem with the Name property of controls at design time. It doesn't work like other properties. My formatter code works fine at runtime, but at design instead of receiving the object's name, I receive a string of the object's type (e.g. if my object is a Button called "CancelButton", at design time Name=="Button" while at run time Name=="CancelButton")

Does anyone know where there is more information on the Name property? Is there any way to obtain the name assigned to the object at design time? Also, is there any way to obtain the name of a component? These have no Name property at runtime, even though there is a property called "(Name)" in the property editor which affects code generation at design time

Thanks
Marku
 
markusszil said:
Does anyone know where there is more information on the Name property? Is there any way to obtain the name assigned to the
object at design time? Also, is there any way to obtain the name of a component? These have no Name property at runtime, even
though there is a property called "(Name)" in the property editor which affects code generation at design time.

TypeDescriptor.GetProperties
 
Thanks, but sorry, I don't understand the response.

I had already been using various reflection methods to obtain the fields, properties, etc. of the controls and components (e.g. Type.GetProperties() ). Is there anything special about TypeDescriptor vs. Type?

As far as I can tell, the Name property appears to be special.

For example, create a form and drop a Timer on it. The Timer has a "(Name)" property which can be changed. Say it's called "Timer1". Now try in the code window to access that name - e.g.

if (Timer1.Name=="Timer1") {...}

This will give an error and will already be flagged during typing because Timer1 has no Name property - but it certainly appears to have such a property since it can be edited at design time (note: there is, of course, no code generation for the Name property, either).

This code will work with controls because they do have a Name property, and it can be both read and set. However, at design time the Name returned by the control is not the name the user assigned but rather the class name of the control.

Once again, I am trying to access the names of controls and components at design time.
 
Back
Top