Font and Color Properties in Custom Controls

B

Bjoern Feld

Hi,

I don't know if this has been asked before.

I created a custom control and added some properties for font and color.
How do I manage to set the default attribute for theese properties for the
designer?

#if NETCFDESIGNTIME

[System.ComponentModel.Category("Caption")]

[System.ComponentModel.DefaultValueAttribute(???)]

[System.ComponentModel.Description("Color of control caption")]

#endif

TIA Bjoern
 
T

Tim Wilson

To do more complex default value checking the designer asks that you use the
ShouldSerializeX and ResetX method naming where X is the same name as the
property. An example for a property with the name "Font" follows.

#if NETCFDESIGNTIME

public bool ShouldSerializeFont()
{
return ((Font.Name != "Tahoma") || (Font.Size != 8F) || (Font.Style !=
FontStyle.Regular));
}

public override void ResetFont()
{
Font = new Font("Tahoma", 8F, FontStyle.Regular);
}

#endif
 
B

Bjoern Feld

Thanks Tim!


Tim Wilson said:
To do more complex default value checking the designer asks that you use the
ShouldSerializeX and ResetX method naming where X is the same name as the
property. An example for a property with the name "Font" follows.

#if NETCFDESIGNTIME

public bool ShouldSerializeFont()
{
return ((Font.Name != "Tahoma") || (Font.Size != 8F) || (Font.Style !=
FontStyle.Regular));
}

public override void ResetFont()
{
Font = new Font("Tahoma", 8F, FontStyle.Regular);
}

#endif

--
Tim Wilson
.Net Compact Framework MVP
{cf147fdf-893d-4a88-b258-22f68a3dbc6a}

Bjoern Feld said:
Hi,

I don't know if this has been asked before.

I created a custom control and added some properties for font and color.
How do I manage to set the default attribute for theese properties for the
designer?

#if NETCFDESIGNTIME

[System.ComponentModel.Category("Caption")]

[System.ComponentModel.DefaultValueAttribute(???)]

[System.ComponentModel.Description("Color of control caption")]

#endif

TIA Bjoern
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top