DefaultValue attribute

T

tinyabs

Hi,

How do it set the default value of PopupSize?

[DefaultValue(typeof(Size), "{Width=192,Height=168}")]

public Size PopupSize

{

get { return FPopupSize; }

set { FPopupSize = value; }

}
 
N

Nicholas Paldino [.NET/C# MVP]

tinyabs,

The DefaultValue attribute is used by the designer to set the default
value.

In order to set the value yourself, you have to get the appropriate
class derived from TypeConverter. In order to do this, take the type
specified in the DefaultValue attribute, and look for the TypeConverter
attribute on that type. This should point to another type which has a
TypeConverter which you can then pass the string value to in order to create
the Size instance (which you will have to cast).

Hope this helps.
 
T

Tim Wilson

You can set the DefaultValue attribute for a property of type Size like
this.

[DefaultValue(typeof(System.Drawing.Size), "192, 168")]
public Size PopupSize
{
...
}
 

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