Click to See Complete Forum and Search --> : DesignTime UserControl [DefaultValue(?)]


Grofit
August 3rd, 2009, 02:28 AM
Hey,

Im just updating some of my user controls and ive just found out about the Browsable and DefaultValue attributes, which are great. However ive got certain properties that are more complex objects, like rectangles and points.

Now im sure that these can be done as alot of the .net controls have points and rectangles as attributes, but whenever i try:


[DefaultValue(new Point(0,0))]
public Point SomeProperty(){...}


It tells me that its an invalid type, which is fair enough as looking through the overloads the closes i can find is using an object type, however ive tried casting the new point to an object and it doesnt seem to like it.

So can anyone shed any light on the right way to do this?

BigEd781
August 3rd, 2009, 03:40 AM
Honestly, I don't know as much about attributes as I probably should, but why not just do something like this? It has the same effect, of course, if you really want the default value to be (0,0) you don't have to do anything at all:


class MyTextBox : TextBox
{
private Point _foo = new Point( 100, 100 );
[Browsable( true )]
public Point Foo { get { return _foo; } set { _foo = value; } }
}

Grofit
August 3rd, 2009, 03:51 AM
Hey,

Yeah could do it that way... i dont *need* default values, just as i found these attributes wondered how they did the complex objects...