有图形化显示,继承WebControl类
System.Web.UI.WebControls.WebControl类
主要属性:
主要方法:
protected virtual void AddAtrributeToRender(HtmlTextWrter writer) 设计样式
protected override void Render(HtmlTextWriter writer) 重写了Render
protected virtual void RenderControls(HtmlTextWriter writer) 显示控件内容. 和子控件
public virtrual void RenderBeginTag(HtmlTextWrtier witer)
public virtrual void RenderEndTag(HtmlTextWrtier witer)
public void ApplyStyle(Style s) 将用户制定的样式复制到控件,如果有重叠,改写控件样式
publie void MergeStyle(Style s) 将制定样式复制到控件,如果有重叠,不改写控件现有的样式元素
public irtualStyleCreateControlStyle() WebControl类内部的样式
主要属性:
属性 | 类型 | 说明 |
Controls | ControlsCollection | 子控件 |
ControlStyle | Style | 样式 |
ControlStyleCreated | bool | 获取一个值,表示是否为ControlStyle创建了一个Style对象 |
Enabled | bool | |
TagKey | HtmlTextWriterTag | 获取与该控件对应的System.Web.UI.HtmlTextWriterTag值 |
主要方法:
protected virtual void AddAtrributeToRender(HtmlTextWrter writer) 设计样式
protected override void Render(HtmlTextWriter writer) 重写了Render
protected virtual void RenderControls(HtmlTextWriter writer) 显示控件内容. 和子控件
public virtrual void RenderBeginTag(HtmlTextWrtier witer)
public virtrual void RenderEndTag(HtmlTextWrtier witer)
public void ApplyStyle(Style s) 将用户制定的样式复制到控件,如果有重叠,改写控件样式
publie void MergeStyle(Style s) 将制定样式复制到控件,如果有重叠,不改写控件现有的样式元素
public irtualStyleCreateControlStyle() WebControl类内部的样式
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web.UI;
namespace USERControls
{
[
DefaultProperty("Text"),
ToolboxData("<{0}:WebCustomerControl runat=server></(0):WebCustomerControl>")
]
public class USERRenderTest2:System.Web.UI.WebControls.WebControl
{
private string text="";
private string href="";
public USERRenderTest2():base(System.Web.UI.HtmlTextWriterTag.Div)
{
}
[
Description("to show text"),
Bindable(true),
Category("Appearance"),
DefaultValue(" ")
]
public string Text
{
get{return text;}
set{text=value;}
}
[
Description("to show href"),
Bindable(true),
Category("Appearance"),
DefaultValue(" ")
]
public string Href
{
get { return href; }
set { href = value; }
}
protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
{
writer.AddStyleAttribute(System.Web.UI.HtmlTextWriterStyle.BorderStyle, "#999 1px solid");
base.AddAttributesToRender(writer);
}
public override void RenderControl(System.Web.UI.HtmlTextWriter writer)
{
writer.AddAttribute("onmouseover", "this.style.cssText='color:red'");
writer.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Href, href);
writer.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.A);
writer.Write(text);
writer.RenderEndTag();
base.RenderControl(writer);
}
}
}
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web.UI;
namespace USERControls
{
[
DefaultProperty("Text"),
ToolboxData("<{0}:WebCustomerControl runat=server></(0):WebCustomerControl>")
]
public class USERRenderTest2:System.Web.UI.WebControls.WebControl
{
private string text="";
private string href="";
public USERRenderTest2():base(System.Web.UI.HtmlTextWriterTag.Div)
{
}
[
Description("to show text"),
Bindable(true),
Category("Appearance"),
DefaultValue(" ")
]
public string Text
{
get{return text;}
set{text=value;}
}
[
Description("to show href"),
Bindable(true),
Category("Appearance"),
DefaultValue(" ")
]
public string Href
{
get { return href; }
set { href = value; }
}
protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
{
writer.AddStyleAttribute(System.Web.UI.HtmlTextWriterStyle.BorderStyle, "#999 1px solid");
base.AddAttributesToRender(writer);
}
public override void RenderControl(System.Web.UI.HtmlTextWriter writer)
{
writer.AddAttribute("onmouseover", "this.style.cssText='color:red'");
writer.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Href, href);
writer.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.A);
writer.Write(text);
writer.RenderEndTag();
base.RenderControl(writer);
}
}
}
Surance Yin@ Surance Center
转载请注明出处
转载请注明出处