zoukankan      html  css  js  c++  java
  • ASP.NET显示渐变图片

    最终效果:

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

    还要准备数据:

    View Code
     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%的宽度。:

    View Code
    <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上: 

    View Code
     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");
        }
  • 相关阅读:
    使用office制作图章公章
    Office英语学习好帮手
    office快速制作简历
    如何使用office2010插入屏幕截图
    office 2010 安装教程
    360wifi使用方法|360wifi使用教程
    在我的电脑里新加一个盘符来隐藏文件夹和文件和秘密
    必应词典3.2去广告备忘笔记(转摘于roustar31)
    ASProtect注册码使用教程|ASProtect SKE(加壳脱壳工具) 2.56 汉化注册版
    ISTool5.3.1汉化版使用教程
  • 原文地址:https://www.cnblogs.com/insus/p/2429442.html
Copyright © 2011-2022 走看看