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");
        }
  • 相关阅读:
    可以兼容ie6的纯CSS三级鼠标悬停显示/隐藏菜单实现
    关于网页中行内元素的基线(baseline)、行高(line-height)、垂直对齐(vertical-align)等
    [z]CSS在Internet Explorer 6, 7 和8中的差别
    POJ 2318--TOYS(二分找点,叉积判断方向)
    博弈论笔记--05--纳什均衡之坏风气与银行挤兑
    博弈论笔记--04--足球比赛与商业合作之最佳对策
    博弈论笔记--03--迭代剔除和中位选民定理
    博弈论笔记--02--学会换位思考
    博弈论笔记--01--五个入门结论
    C++新闻检索类
  • 原文地址:https://www.cnblogs.com/insus/p/2429442.html
Copyright © 2011-2022 走看看