自定义控件Img

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>");
    }
   }
  }
 }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值