比较好看吧.
根据书上例子自己写了一下,用VS2005写,特别方便,代码如下
using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
namespace ClingingBoy
{
[DefaultProperty("text"),
ToolboxData("")]
///
/// cingmenu 的摘要说明
///
public class Cingmenu:WebControl
{
#region 定义变量
private string text = "";
private string href = "";
private string width = "20%";
private string height = "";
private string fontfamily = "宋体";
private string fontsize = "12px";
private string target = "_self";
private bool displayPipe = true;
#endregion
#region 构造函数
public Cingmenu():base(HtmlTextWriterTag.Div)
{
}
#endregion
#region 定义属性
[Description("该属性用于表示控件显示的文字内容"),
Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}
[Description("该属性用于表示控件的链接地址"),
Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Href
{
get
{
return href;
}
set
{
href = value;
}
}
[Description("该属性用于表示控件显示的文字大小"),
Bindable(true),
Category("Appearance"),
DefaultValue("12px")]
public string FontSize
{
get
{
return fontsize;
}
set
{
fontsize = value;
}
}
[Description("该属性用于表示控件显示的文字字体类型"),
Bindable(true),
Category("Appearance"),
DefaultValue("宋体")]
public string FontFamily
{
get
{
return fontfamily;
}
set
{
fontfamily = value;
}
}
[Description("该属性用于表示控件的链接的目标框架"),
Bindable(true),
Category("Appearance"),
DefaultValue("宋体")]
public string Target
{
get
{
return target;
}
set
{
target = value;
}
}
[Description("该属性用于表示控件是否显示分隔符 | "),
Bindable(true),
Category("Appearance"),
DefaultValue("true")]
public bool DisplayPipe
{
get
{
return displayPipe;
}
set
{
displayPipe = value;
}
}
#endregion
protected override void AddAttributesToRender(HtmlTextWriter output)
{
//定义控件div的样式style="WHITE-SPACE: nowrap;BORDER-TOP: #999 1px solid;BACKGROUND: #f1f1f1; PADDING-BOTTOM: 2px; PADDING-TOP: 1px; BORDER-BOTTOM: #999 1px solid"
output.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, "#f1f1f1");
output.AddStyleAttribute("white-space", "nowrap");
output.AddStyleAttribute("BORDER-TOP", "#999 1px solid");
output.AddStyleAttribute("BORDER-BOTTOM", "#999 1px solid");
output.AddStyleAttribute("PADDING-BOTTOM", "2px");
output.AddStyleAttribute("PADDING-TOP", "2px");
本文转自:http://www.5uflash.com/flashjiaocheng/Flashyingyongkaifa/785.html