The controls we develop generally need to interact with the people programmers who use the controls, where there are two ways to interact: one is a property and the other is an event. Properties can be simple types such as int, string, and other types that are not too complex, and there are more complex types such as: collections.
One, property implementation interaction
We still use the example above to add a property picshow example:
public class Picshow:control
{
private string _imgurl
//property
Public virtual string Imgurl
{ br> get
{
return this._imgurl;
}
Set
{
This._imgurl = value;
}
}
protected override void Render (HtmlTextWriter writer)
{
Writer. AddStyleAttribute (htmltextwriterstyle.textalign, "center");
Writer. AddStyleAttribute (Htmltextwriterstyle.height, "100px");
Writer. AddStyleAttribute (Htmltextwriterstyle.width, "100px");
Writer. RenderBeginTag (HTMLTEXTWRITERTAG.DIV);
//create Img Tag
Writer. AddAttribute (HTMLTEXTWRITERATTRIBUTE.SRC, this. Imgurl);
Writer. AddStyleAttribute (Htmltextwriterstyle.width, "80px");
Writer. AddStyleAttribute (Htmltextwriterstyle.height, "80px");
Writer. RenderBeginTag (HTMLTEXTWRITERTAG.IMG);
Writer. RenderEndTag ();
//end of Div
Writer. RenderEndTag ();
}
}
The example above is to change the last control can only specify dead pictures, so that the address of the picture can be specified by the user of the control itself. A private field is defined in the control, and its value is set by the property Imgurl because we allow the property to be overridden, so it is defined as a virtual type. The definition of a property here is the same as that of a generic class, and there is no more explanation.