用ASPNET編寫能夠顯示圖標漸變的效果簡單實用詳細請看下文
最終效果
實現效果首先准備一張圖片高度為pixel寬度為至pixel漸變的圖片還要准備數據
Dictionary<int int> Datas
{
get
{
Dictionary<int int> d = new Dictionary<int int>();
dAdd( );
dAdd( );
dAdd( );
return d;
}
}
ok數據准備完了在aspx裡放三個Label控件當然你可以顯示在其它控件或是標簽中有一點要注意的是Width=它是漸變圖片在%的寬度
<asp:Label ID=Label runat=server style=margin: px; Text= Width= BorderWidth=></asp:Label><br />
<asp:Label ID=Label runat=server style=margin: px; Text= Width= BorderWidth=></asp:Label><br />
<asp:Label ID=Label runat=server style=margin: px; Text= Width= BorderWidth=></asp:Label><br />
把數據顯示於Label上
protected void Page_Load(object sender EventArgs e)
{
Data_Binding();
}
private void Data_Binding()
{
int totals = ;
foreach (KeyValuePair<int int> kvp in Datas)
{
double rate = kvpValue / (double)totals;
double width = rate * ;
switch (kvpKey)
{
case :
thisLabelText = GradientImage(width rate);
break;
case :
thisLabelText = GradientImage(width rate);
break;
case :
thisLabelText = GradientImage(width rate);
break;
}
}
}
private string GradientImage(double width double rate)
{
return <IMG height= src=images/bargif width= + width + align=absMiddle> + rateToString(p);
}
From:http://tw.wingwit.com/Article/program/net/201311/12448.html