您的位置:首页 > 编程语言

.NET 页面中用代码画图用来表示百分比例[WEB学习示例]

2008-10-19 10:51 393 查看
protected void Page_Load(object sender, EventArgs e)
{

int height = 600, width = 600;
System.Drawing.Bitmap image = new System.Drawing.Bitmap(height, width);
Graphics g = Graphics.FromImage(image);
g.Clear(Color.Wheat);
Font font = new System.Drawing.Font("Arial", 9, FontStyle.Regular);
Font font1 = new System.Drawing.Font("隶书", 20, FontStyle.Regular);
System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.Blue, 1.2f, true);
g.FillRectangle(Brushes.WhiteSmoke, 0, 0, width, height);
Brush brush1 = new SolidBrush(Color.Blue);
g.DrawString("" + "统计统计统计统计统计", font1, brush1, new PointF(100, 30));
g.DrawRectangle(new Pen(Color.Blue), 0, 0, image.Width - 1, image.Height - 1);
Pen mypen = new Pen(brush, 1);
int x = 100;
for (int i = 0; i < 11; i++)
{ g.DrawLine(mypen, x, 80, x, 340); x = x + 40; }
Pen mypen1 = new Pen(Color.Blue, 2);
g.DrawLine(mypen1, x - 480, 80, x - 480, 340);
int y = 106;
for (int i = 0; i < 9; i++)
{ g.DrawLine(mypen, 60, y, 540, y); y = y + 26; }
g.DrawLine(mypen1, 60, y, 540, y);
string[] n = { "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月" };
x = 62;
for (int i = 0; i < 12; i++)
{ g.DrawString(n[i].ToString(), font, Brushes.Red, x, 348); x = x + 40; }
string[] m = { "100%", "90%", "80%", "70%", "60%", "50%", "40%", "30%", "20%", "10%", "0%" };
y = 85;
for (int i = 0; i < 11; i++)
{ g.DrawString(m[i].ToString(), font, Brushes.Red, 25, y); y = y + 26; }
//
System.IO.MemoryStream ms = new System.IO.MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
Response.ClearContent();
Response.BinaryWrite(ms.ToArray());

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐