Drawing;
namespace ControlsBook2Lib.Ch02
{
[ToolboxData("<{0}:textbox3d runat=server>{0}:textbox3d>"),
ToolboxBitmap(typeof(ControlsBook2Lib.Ch02.TextBox3d),
"ControlsBook2Lib.Ch03.TextBox3d.bmp")]
public class TextBox3d : TextBox// Inherit from rich control
{
public TextBox3d()
{
Enable3D = true;
}
// Custom property to set 3D appearance
[DescriptionAttribute("Set to true for 3d appearance"), DefaultValue("True")]
public bool Enable3D
{
get
{
object enable3D = ViewState["Enable3D"];
if (enable3D == null)
return false;
else
return (bool)enable3D;
}
set
{
76 CHAPTER 2 ?– ENCAPSULATING FUNCT IONALITY IN A SP.NET
ViewState["Enable3D"] = value;
}
}
protected override void Render(HtmlTextWriter output)
{
// Add DHTML style attribute
if (Enable3D)
output.AddStyleAttribute("FILTER", "progid:DXImageTransform.Microsoft.
dropshadow(OffX=2, OffY=2, Color='gray', Positive='true'");
base.Render(output);
}
}
}
In our inheritance example, we have two main features: a property called Enable3D and an
overridden Render() method. The property is used to determine whether or not to render with
a 3-D look. Providing a Boolean property that allows the developer to revert to the default
behavior of the base class server control is a good design guideline to follow when inheriting
from rich server controls in ASP.
Pages:
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145