ASP.NET显示渐变图片

最终效果:

 

实现效果,首先准备一张图片,高度为25pixel,宽度为1至3pixel渐变的图片。可以这里下载

还要准备数据:

复制代码
 Dictionary< intint> Datas
    {
         get
        {
            Dictionary< intint> d =  new Dictionary< intint>();
            d.Add( 135);
            d.Add( 245);
            d.Add( 320);
             return d;
        }
    }
复制代码

 

ok,数据准备完了,在aspx里放三个Label控件,当然你可以显示在其它控件或是标签中,有一点要注意的是Width="300",它是渐变图片在100%的宽度。:

< asp:Label  ID ="Label1"  runat ="server"  style ="margin: 3px;"  Text =""  Width ="300"  BorderWidth ="1" ></ asp:Label >< br  />
         < asp:Label  ID ="Label2"  runat ="server"  style ="margin: 3px;"  Text =""  Width ="300"  BorderWidth ="1" ></ asp:Label >< br  />
         < asp:Label  ID ="Label3"  runat ="server"  style ="margin: 3px;"  Text =""  Width ="300"  BorderWidth ="1" ></ asp:Label >< br  />

 

把数据显示于Label上: 

复制代码
  protected  void Page_Load( object sender, EventArgs e)
    {
        Data_Binding();
    }

     private  void Data_Binding()
    {
         int totals =  100;
         foreach (KeyValuePair< intint> kvp  in Datas)
        {
             double rate = kvp.Value / ( double)totals;

             double width = rate *  300;
             switch (kvp.Key)
            {
                 case  1:
                     this.Label1.Text = GradientImage(width, rate);
                     break;
                 case  2:
                     this.Label2.Text = GradientImage(width, rate);
                     break;
                 case  3:
                     this.Label3.Text = GradientImage(width, rate);
                     break;
            }
        }
    }

     private  string GradientImage( double width,  double rate)
    {
         return  " <IMG height='21' src='images/bar.gif' width=' " + width +  " ' align='absMiddle'>  " + rate.ToString( " p ");
    }

复制代码


http://www.cnblogs.com/insus/archive/2012/04/01/2429442.html


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值