Groups | Blog | Home
all groups > dotnet windows forms designtime > september 2006 >

dotnet windows forms designtime : Custom type property in property editoe (like Font in Control)


zofcentr
9/25/2006 8:32:02 AM
Hi,
I am traying t ocreate similar property as Font in TextBox. I have created
custom class with two private strings fields and coresponding properties. I
have added attribute Serializable to this class as in Font calss. Then I have
created control with private member of above mentioned class and public
property for this memeber.
After compilation and placing this control on form a see property but I
can;t edit value of this property like in Font property.

Thanks in advance for help
zofcentr
Frank Loizzi
9/25/2006 9:20:23 PM
Am Mon, 25 Sep 2006 08:32:02 -0700 schrieb zofcentr:

[quoted text, click to view]

To create a property with automatically assigned font UI-TypeEditor, you
have to create a public property in your custom class with type of font,
not string.

public Font MyFont
{
get {return this.m_myFont; }
set {this.m_myFont = value; }
}

Visual Studio is using the pre-created FontEditor UI-TypeEditor from the
System.Drawing.Design assembly. You have to implement your property like
mentioned. Or you have to implement a custom FontEditor UI-TypeEditor. If
you do that, you have to derive from UITypeEditor or FontEditor class.

Bye

Frank Loizzi
zofcentr
9/26/2006 11:20:01 PM
Hello Frank,
I don't want to create Font type property but Custom type property which is
serialized by designer like Font property or Size property. For this
properties desinger creates creates code which sets value of property wich
new created object eg. this.Size = new Size(10,10);
I wont my own class which will be serialized by designer like mentioned.

Thanks in advance
zofcentr


[quoted text, click to view]


Frank Loizzi
9/27/2006 12:00:00 AM
Am Tue, 26 Sep 2006 23:20:01 -0700 schrieb zofcentr:

[quoted text, click to view]

Add this above the public property:

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

That's all you have to do.

Bye

Frank Loizzi
zofcentr
10/2/2006 3:47:01 AM
I have this attribut applied to property. But this does not help. I see
property in properties window but I cannot edit it. I can't even expand it
like font property to see object details.


[quoted text, click to view]
Frank Hileman
10/2/2006 3:05:44 PM
Create a custom TypeConverter, and when an InstanceDescriptor type is
requested, create an InstanceDescriptor describing how to serialize your
object. Associate the TypeConverter with your class with an attribute. Read
more here:
http://msdn.microsoft.com/library/en-us/dndotnet/html/vsnetpropbrow.asp


Regards,
Frank Hileman

check out VG.net: http://www.vgdotnet.com
Animated vector graphics system
Integrated Visual Studio graphics editor

[quoted text, click to view]

zofcentr
10/4/2006 3:23:12 AM
Thanks Frank,
This is what I was looking for.

Do YOU know maybe how to change behavior of designer serialization.
Normaly serializer creates code like that :

myComponent.CustomProperty = new CustomPropertyData(.....);
I would like to avoid creating complex constructor for every comlex property
object and have a code like below :

myComponent.CustomProperty = new CustomPropertyData();<- default constructor
myComponent.CustomProperty.FirstName = "John";
myComponent.CustomProperty.LastName = "Smith";

Thanks in advance
zofcentr





[quoted text, click to view]
Frank Hileman
10/15/2006 10:54:15 AM
Hi,

The third parameter to the InstanceDescriptor constructor is a boolean
called isComplete. Set that to false and the code generator will create a
local variable, then use the usual DefaultValue and ShouldSerialize logic to
determine if the property values must be serialized.

Regards,
Frank Hileman

check out VG.net: http://www.vgdotnet.com
Animated vector graphics system
Integrated Visual Studio graphics editor

[quoted text, click to view]

zofcentr
10/19/2006 12:14:02 AM
Thanks Frank,
Ia ma really grateful for help.

Best regrads

zofcentr


[quoted text, click to view]
AddThis Social Bookmark Button