| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 7880 人关注过本帖
标题:ASP.NET动态生成进度条图片
只看楼主 加入收藏
jacklee
Rank: 7Rank: 7Rank: 7
来 自:XAplus
等 级:贵宾
威 望:32
帖 子:1769
专家分:104
注 册:2006-11-3
结帖率:100%
收藏
 问题点数:0 回复次数:32 
ASP.NET动态生成进度条图片

效果图片:

图片附件: 游客没有浏览图片的权限,请 登录注册


//Jack.Lee 2007-10-28
using System;
using System.Drawing;
using System.Drawing.Drawing2D;

/// <summary>
/// this class for build Some pictures for web-ui
/// </summary>
public class UIMaps
{
public UIMaps()
{
}

/// <summary>
/// Build a progress width this value in UIProgressProperty structure
/// </summary>
/// <param name="uiprspty">Property</param>
/// <returns>a bitmap</returns>
public Bitmap BuildDefault(UIProgressProperty uiprspty)
{
if (uiprspty.Width <= 5 || uiprspty.Height <= 3)
return null;
#region Init
//Measure Value
int rValueWidth = 0;
if (uiprspty.Value <= 0)
{
rValueWidth = 0;
uiprspty.Value = 0;
}
else if (uiprspty.Value > uiprspty.maxValue)
{
rValueWidth = uiprspty.Width;
uiprspty.Value = uiprspty.maxValue;
}
else
rValueWidth = (int)((float)((float)uiprspty.Value / (float)uiprspty.maxValue) * uiprspty.Width); //real length of data
//Caption
uiprspty.Text += Convert.ToString((int)(((float)uiprspty.Value / (float)uiprspty.maxValue) * 100)) + "%"; //%20

Bitmap map = new Bitmap(uiprspty.Width, uiprspty.Height);
Graphics g = Graphics.FromImage(map);
g.InterpolationMode = InterpolationMode.HighQualityBilinear;

//background
g.FillRectangle(new SolidBrush(uiprspty.backColor),
new Rectangle(0, 0, uiprspty.Width, uiprspty.Height));
#endregion

#region datas
//datas
//g.FillRectangle(new SolidBrush(uiprspty.fColor1),
// new Rectangle(0, 1, rValueWidth, uiprspty.Height - 2));

Rectangle topleftrc = new Rectangle(1, 1, rValueWidth / 2, uiprspty.Height / 2);
if (topleftrc.Width <= 0) topleftrc.Width = 1;
LinearGradientBrush topleft = new LinearGradientBrush(topleftrc,
uiprspty.fColor1, uiprspty.fColor2,
LinearGradientMode.ForwardDiagonal);

Rectangle toprgtrc = new Rectangle((rValueWidth / 2) + 1, 1, rValueWidth / 2, uiprspty.Height / 2);
if (toprgtrc.Width <= 0) toprgtrc.Width = 1;
LinearGradientBrush toprgt = new LinearGradientBrush(toprgtrc,
uiprspty.fColor1, uiprspty.fColor2,
LinearGradientMode.BackwardDiagonal);

Rectangle btmleftrc = new Rectangle(1, (uiprspty.Height / 2) - 1, rValueWidth / 2, uiprspty.Height / 2);
if (btmleftrc.Width <= 0) btmleftrc.Width = 1;
LinearGradientBrush btmleft = new LinearGradientBrush(btmleftrc,
uiprspty.fColor2, uiprspty.fColor1, LinearGradientMode.BackwardDiagonal);

Rectangle btmrgtrc = new Rectangle((rValueWidth / 2) + 1, (uiprspty.Height / 2) - 1, rValueWidth / 2, uiprspty.Height / 2);
if (btmrgtrc.Width <= 0) btmrgtrc.Width = 1;
LinearGradientBrush btmrgt = new LinearGradientBrush(btmrgtrc,
uiprspty.fColor2, uiprspty.fColor1, LinearGradientMode.ForwardDiagonal);

g.FillRectangle(topleft, topleftrc);
g.FillRectangle(toprgt, toprgtrc);
g.FillRectangle(btmleft, btmleftrc);
g.FillRectangle(btmrgt, btmrgtrc);

topleft.Dispose();
toprgt.Dispose();
btmleft.Dispose();
btmrgt.Dispose();
#endregion

#region paint text
if (uiprspty.showText)
{
if (uiprspty.Text != null || uiprspty.Text.Trim() != "")
{
SizeF szf = g.MeasureString(uiprspty.Text, uiprspty.textFont);
int leftp = (int)szf.Width > uiprspty.Width ? 1 : (uiprspty.Width - (int)szf.Width) / 2;
int toppx = (int)szf.Height > uiprspty.Height ? 1 : (uiprspty.Height - (int)szf.Height) / 2;
g.DrawString(uiprspty.Text, uiprspty.textFont,
new SolidBrush(uiprspty.foreColor), (float)leftp, (float)toppx);
}
}
#endregion

//border
g.DrawRectangle(new Pen(uiprspty.borderColor),
new Rectangle(0, 0, uiprspty.Width - 1, uiprspty.Height - 1));

#region SaveMap
//ptr disponse
g.Dispose();
GC.Collect();

//save?
if (uiprspty.bSave)
{
try
{
map.Save(uiprspty.path, System.Drawing.Imaging.ImageFormat.Png);
uiprspty.bSaved = true;
}
catch
{
uiprspty.bSaved = false;
}
}
#endregion
return map;
}
}

public struct UIProgressProperty
{
public int Width;
public int Height;
public bool showText;
public string Text;
public Font textFont;
public Color foreColor;
public Color fColor1;
public Color fColor2;
public Color borderColor;
public Color backColor;

public int Value;
public int maxValue;

public bool bSave;
public bool bSaved;
public string path;

public void SetValueAndSave(int value, int maxvalue, bool save, string savepath)
{
Value = value;
maxValue = maxvalue;
bSave = save;
path = savepath;
}

public void SetThemeOrange(int ctlWidth, int ctlHeight)
{
Width = ctlWidth;
Height = ctlHeight;
showText = true;
textFont = new Font("Arial", 9f);
Text = "";
foreColor = Color.OrangeRed;
borderColor = Color.OrangeRed;
backColor = Color.White;
fColor1 = Color.Orange;
fColor2 = Color.White;
}
public void SetThemeGreen(int ctlWidth, int ctlHeight)
{
Width = ctlWidth;
Height = ctlHeight;
showText = true;
textFont = new Font("Arial", 9f);
Text = "";
foreColor = Color.Green;
borderColor = Color.Green;
backColor = Color.White;
fColor1 = Color.FromArgb(16, 217, 3);
fColor2 = Color.White;
}
}


[此贴子已经被作者于2007-10-29 12:03:14编辑过]

搜索更多相关主题的帖子: NET 进度 ASP 动态 
2007-10-29 12:01
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
不错啊..呵,学习

飘过~~
2007-10-29 13:01
sam0802
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2006-7-29
收藏
得分:0 
看不懂

2007-10-29 18:11
垃圾的沉默
Rank: 1
等 级:新手上路
威 望:2
帖 子:511
专家分:0
注 册:2007-6-25
收藏
得分:0 

努力学习当中


人们笑我太疯癫...我笑人们太正经
2007-10-29 18:39
jacklee
Rank: 7Rank: 7Rank: 7
来 自:XAplus
等 级:贵宾
威 望:32
帖 子:1769
专家分:104
注 册:2006-11-3
收藏
得分:0 
就一个结构和一个类,现实的来说是一个函数。。。函数调用结构。不难.GDI。

XAplus!
讨论群:51090447
删吧删吧,把我的号给删了!
2007-10-30 07:53
Hunt
Rank: 1
等 级:新手上路
威 望:1
帖 子:199
专家分:9
注 册:2004-11-23
收藏
得分:0 
目前还看不懂,呵呵,刚开始学习网页,才上了没有几节课

程序人生最高境界:“我就是程序,程序就是我。”
2007-10-30 18:26
jacklee
Rank: 7Rank: 7Rank: 7
来 自:XAplus
等 级:贵宾
威 望:32
帖 子:1769
专家分:104
注 册:2006-11-3
收藏
得分:0 
这也不完全算是WEB。是和WIN共享。。。

XAplus!
讨论群:51090447
删吧删吧,把我的号给删了!
2007-10-30 20:15
lilyguaiguai
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2006-12-9
收藏
得分:0 
学习学习!

2007-10-31 15:48
guoxhvip
Rank: 8Rank: 8
来 自:聖西羅南看臺
等 级:贵宾
威 望:44
帖 子:4052
专家分:135
注 册:2006-10-8
收藏
得分:0 
学习学习

愛生活 && 愛編程
2007-10-31 16:34
skylence
Rank: 1
等 级:新手上路
帖 子:92
专家分:0
注 册:2006-11-15
收藏
得分:0 
弄下来玩玩  呵呵  谢谢啊

2007-11-09 22:08
快速回复:ASP.NET动态生成进度条图片
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022853 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved