使用GDI畫座標曲線

來源:互聯網
上載者:User
代碼

//畫速度曲線
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畫圖是相當方便的

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.