custom properties , usercontrols

2

2G

Hi,

I have a usercontrol with a custom propertie but in the designer, the
properties doesn't expand it's properties so I can't change them. I've
search google on this and came across things like
DesignerSerializationVisibilityAttribute and Type/ReferenceConverters but
can't find a good example on how to actually do this and don't know if this
is what I need.
Also, after it is possible to change the property in the designer, will the
change be saved in the code? I've had previous problems where I could change
the property (when the property class inherits from Component) but the
changes were not saved.


public class UserControl1: UserControl{

public UserControl1(){}

private Border border;

[Browsable(true),

DesignerSerializationVisibilityAttribute(DesignerSerializationVisibilityAttr
ibute.Content]
public Border Border{
get{ return this.border; }
set{
this.border = value;
}
}
}

[DefaultPropertie("Color")]
public class Border{

public Border():this(Color.Black){}

public Border(Color c){
this.Color = c;
}

private Color color;

[Category("Appearance"),
Browsable(true)]
public Color Color{
get{ return this.color; }
set{ this.color = value; }
}
}

thanks.
 
M

Mohamoss

hi 2G!!
you can use the property attributes that should be used with user
controls
The following is a list of some of the property attributes and their
descriptions.
Property Attributes Description
Browsable Specifies whether a property or an event
should be displayed in the Properties
window.
Category Specifies the name of the category in
which to group a property or event. When
categories are used, component properties
and events can be displayed in logical
groupings in the Properties window.
Description Defines a small block of text to be
displayed at the bottom of the Properties
window when the user selects a property
or event.
DefaultProperty( I guess you do use that one ) Specifies the default
property for the
component. This property is selected in
the Properties window when a user clicks
the control.
DefaultValue Sets a default value for a property.
TypeConverter Specifies the type converter to use for
converting the type of the property to
another data type.
Editor Specifies the editor to use for editing
(changing) a property in the Visual
Designer.
RefreshProperties Indicates how a designer refreshes when
the associated property value changes.
This class cannot be inherited.


You can use this this way
[Category("Appearance")]public Color MyBackColor // your implementation

And this way I belive your design time changes will persist in the code
…….

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 

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