How to Implement ASP. NET to display gradient Images,

Source: Internet
Author: User

How to Implement ASP. NET to display gradient Images,

First, let's get the final result:

To achieve the effect, first prepare an image with a height of 25 pixel and a gradient of 1 to 3 pixel. You can download it here.

Prepare the data as follows:

Dictionary<int, int> Datas  {  get  {   Dictionary<int, int> d = new Dictionary<int, int>();   d.Add(1, 35);   d.Add(2, 45);   d.Add(3, 20);   return d;  }  } 

OK, the data is ready. put three Label controls in aspx. Of course, you can display them in other controls or labels. Note that Width = "300 ", it is the gradient image width at 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 /> 

Display the data on the Label:

protected void Page_Load(object sender, EventArgs e)  {  Data_Binding();  }   private void Data_Binding()  {  int totals = 100;  foreach (KeyValuePair<int, int> 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 " " + rate.ToString("p");  } 

The above is how ASP. NET implements gradient images, hoping to help you learn.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.