[RESOLVED] Custom object, set properties in designer?
Hi, I have made a control which inherits container. this control has an object called ColorTable as a public property. The ColorTable object has some Color and Boolean properties. I want to be able to edit these in the designer but cant, is there something I can do in the class decloration or something?
The ColorTable property just appears gray in the designer and I cant edit it.
Any help would be appreciated.
Thanks.
Re: Custom object, set properties in designer?
Yep!
See the link below, its in VB but the adoration is the same. You need to adorn each property that you want to be shown with the position in the property window and the description.
http://www.vbforums.com/showthread.p...ight=Hot+Label
Also as far as I know it is only when you build the control that these show. There are also other adorns in that code as you will see.
Re: Custom object, set properties in designer?
I think you're talking about something like the way the Size and Font properties of a control expand to let you edit "sub-properties", correct? If so, I think it actually has something to do with the TypeConverter attribute applied to the type of the property. You'll note that the Font class and the Size structure both have the TypeConverter attribute applied. I could be wrong about this but I seem to recall that I've looked at this some time in the dim, dark past. Assuming I'm correct, you'll have to apply the TypeConverter attribute to your ColorTable class in order for it to behave the same way in the Properties window.
If you want something more advanced then you could create a custom UITypeEditor for that class.
Re: Custom object, set properties in designer?
hmmm my example gave the correct convertors automatically, but then they where simple properties eg the hotcolor is actually a color object. A simple test would be to adorn a font propertie and see if it auto implements.
Re: Custom object, set properties in designer?
Quote:
Originally Posted by
DeanMc
hmmm my example gave the correct convertors automatically, but then they where simple properties eg the hotcolor is actually a color object. A simple test would be to adorn a font propertie and see if it auto implements.
It's got nothing to do with the properties themselves, but rather the types of the properties. Like I said, the Font class and the Size structure are decorated with the TypeConverter attribute so any properties of type Font or type Size will behave that way in the designer. If you define a class Thing and you want properties that are type Thing to behave that way in the designer then you have to decorate the Thing class with the TypeConverter attribute.
Re: Custom object, set properties in designer?
sorry my post is unclear. I was agreeing with you. The property and backing variable was of the type color so the adornment checked that type and gave a color dialog. I had a book with a chapter on type converters il try to root it out.
Re: Custom object, set properties in designer?
Thanks, these posts put me on the right track, after a quick search I found this document on MSDN. http://msdn.microsoft.com/en-us/library/a19191fh.aspx
After a skim read I found the attributes I am supposed to use are the [TypeConverter] attribute declared on members or the class decloration and the [Designer] attribute (only on class decoration) for a custom designer dialog (I think), which is cool because I have already built a dialog for visually design of these color table objects...
I will have to read the article in depth, as I didnt get all of it.
Thanks people...
Re: [RESOLVED] Custom object, set properties in designer?
Ah, so you can apply the TypeConverter attribute to properties as well as types. That I didn't know but, now that I think of it, it makes sense. Otherwise you couldn't change the design-time behaviour of existing classes. I may have done DeanMc a disservice on that.
Re: [RESOLVED] Custom object, set properties in designer?
Ah sure not to worry! I was hazy on type converters myself!
Re: [RESOLVED] Custom object, set properties in designer?
If you just want to create a property that can be expanded, all you need to do is have that property use the ExpandableObjectConverter type converter. You could create your own TypeConvert and have it inherit from ExpandableObjectConverter, but unless you need any specific functionality, there is no need for that.
I've only used this in VB but I don't think it shoudl be any different in C#:
Code:
private SomeClass _expandableProperty = new SomeClass();
[TypeConverter(ExpandableObjectConverter)]
public SomeClass MyExpandableProperty
{
get { return _expandableProperty; }
set { _expandableProperty = value; } // I'm not sure if you need a Set, don't think so!
}
The syntax might be a little wonky, but that should get you on track.