本文共 2165 字,大约阅读时间需要 7 分钟。
using System;
using System.Web.UI;using System.Web.UI.WebControls;using System.ComponentModel;namespace blackflash{
/// <summary> /// Img 的摘要说明。 /// </summary> [DefaultProperty("Text"), ToolboxData("<{0}:Img runat=server></{0}:Img>")] public class Img : Control, IAttributeAccessor { [Bindable(true), Category("Appearance"), DefaultValue("")] public String Src { get { return (String)ViewState["Src"]; } set { ViewState["Src"] = value; } } public String Href { get { return (String)ViewState["Href"]; } set { ViewState["Href"] = value; } } public String Align { get { return (String)ViewState["align"]; } set { ViewState["align"] = value; } } public String Alpha { get { return (String)ViewState["alpha"]; } set { ViewState["alpha"] = value; } } public String Target { get { return (String)ViewState["Target"]; } set { ViewState["Target"] = value; } } public void SetAttribute(String name, String value1) { ViewState[name] = value1; } public String GetAttribute(String name) { return (String)ViewState[name]; }/// <summary>
/// 将此控件呈现给指定的输出参数。 /// </summary> /// <param name="output"> 要写出到的 HTML 编写器 </param> protected override void Render(HtmlTextWriter output) { if (this.Src !="") { if (this.Href !=null) { output.Write("<a"); output.Write(" href='"+this.Href+"'"); if (this.Target !=null) { output.Write(" target='"+this.Target+"'"); } output.Write(">"); } output.Write("<img "); if (this.Src !=null) { output.Write("src='"+this.Src+"'"); }if (this.Alpha !=null)
{ string[] strAlpha = this.Alpha.Split(','); output.Write("style='filter:alpha(opacity="+strAlpha[0]+")' οnmοuseοver='this.filters.Alpha.opacity=/""+strAlpha[1]+"/"' οnmοuseοut='this.filters.Alpha.opacity=/""+strAlpha[0]+"/"' "); } if (this.Align !=null) { output.Write(" align='"+this.Align+"'"); } if ((String)ViewState["style"] != null) { output.Write(" style='"+(String)ViewState["style"]+"'"); } if ((String)ViewState["width"] != null) { output.Write(" width='"+(String)ViewState["width"]+"'"); } if ((String)ViewState["height"] != null) { output.Write(" height='"+(String)ViewState["height"]+"'"); } output.Write(" border='0' />"); if (this.Href !=null) { output.Write("</a>"); } } } }}转载地址:http://bbptd.baihongyu.com/