最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

ASP.NET显示渐变图片实现方法

来源:动视网 责编:小采 时间:2020-11-27 22:38:16
文档

ASP.NET显示渐变图片实现方法

ASP.NET显示渐变图片实现方法:先给大家来个最终效果: 实现效果,首先准备一张图片,高度为25pixel,宽度为1至3pixel渐变的图片。可以这里下载。 还要准备数据: Dictionary<int, int> Datas { get { Dictionary<int, int> d = new Dictio
推荐度:
导读ASP.NET显示渐变图片实现方法:先给大家来个最终效果: 实现效果,首先准备一张图片,高度为25pixel,宽度为1至3pixel渐变的图片。可以这里下载。 还要准备数据: Dictionary<int, int> Datas { get { Dictionary<int, int> d = new Dictio


先给大家来个最终效果:

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

还要准备数据:

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,数据准备完了,在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<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 "<IMG height='21' src='images/bar.gif' width='" + width + "' align='absMiddle'> " + rate.ToString("p"); 
 } 

文档

ASP.NET显示渐变图片实现方法

ASP.NET显示渐变图片实现方法:先给大家来个最终效果: 实现效果,首先准备一张图片,高度为25pixel,宽度为1至3pixel渐变的图片。可以这里下载。 还要准备数据: Dictionary<int, int> Datas { get { Dictionary<int, int> d = new Dictio
推荐度:
标签: 图片 显示 实现
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top