精于工作、勤于思考

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

代码
//画速度曲线
Graphics g = e.Graphics;
g.DrawLine(Pens.White,
40, picChart.ClientRectangle.Height - 10, picChart.Width - 40, picChart.ClientRectangle.Height - 10);
g.DrawLine(Pens.White,
40, picChart.ClientRectangle.Height - 50, picChart.Width - 40, picChart.ClientRectangle.Height - 50);
g.DrawLine(Pens.White,
40, picChart.ClientRectangle.Height - 90, picChart.Width - 40, picChart.ClientRectangle.Height - 90);
g.DrawLine(Pens.White,
40, picChart.ClientRectangle.Height - 130, picChart.Width - 40, picChart.ClientRectangle.Height - 130);

Pen p
= new Pen(Color.White, 1);
//p.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
//p.DashCap = System.Drawing.Drawing2D.DashCap.Flat;
AdjustableArrowCap aac = new AdjustableArrowCap(5, 5, false);//箭头的大小可以自己随便定义
p.CustomEndCap = aac;
g.DrawLine(p,
40, picChart.ClientRectangle.Height, 40, 4);
g.DrawLine(p, picChart.Width
- 40, picChart.ClientRectangle.Height, picChart.Width - 40, 4);
p.Dispose();

Font f
= new Font("Arial", 9);
//画线上箭头文字
int stepY = (picChart.Height - 150) / 13;
int curH = 0;
StringFormat sf
= new StringFormat();
sf.Alignment
= StringAlignment.Far;
int du = 0;
for (int i = 0; i < 13; i++)
{
bool jo = i % 2 == 0;
int w = jo ? 10 : 5;
g.DrawLine(Pens.White,
40 - w, picChart.ClientRectangle.Height - 130 - curH, 40, picChart.ClientRectangle.Height - 130 - curH);
g.DrawLine(Pens.White, picChart.Width
- 40, picChart.ClientRectangle.Height - 130 - curH, picChart.Width - (40 - w), picChart.ClientRectangle.Height - 130 - curH);

if (jo)
{
//如果是偶数
g.DrawString(du.ToString(), f, new SolidBrush(Color.White), 30, picChart.ClientRectangle.Height - 137 - curH, sf);
g.DrawString(du.ToString(), f,
new SolidBrush(Color.White), picChart.Width - 30, picChart.ClientRectangle.Height - 137 - curH);

du
+= 40;
}

curH
+= stepY;
}


g.DrawString(
"道桥隧", f, new SolidBrush(Color.White), 0, picChart.ClientRectangle.Height - 30);
g.DrawString(
"曲 线", f, new SolidBrush(Color.White), 0, picChart.ClientRectangle.Height - 70);
g.DrawString(
"纵断面", f, new SolidBrush(Color.White), 0, picChart.ClientRectangle.Height - 110);
f.Dispose();

 

在winform程序中,只要了解了那几个类,使用GDI画图是相当方便的

posted on 2010-09-28 11:45  whinsh  阅读(752)  评论(0编辑  收藏  举报