HOW TO:繪製基本曲線

更新:2007 年 11 月

基本曲線是指平滑通過一組指定點的曲線。若要繪製基本曲線,請建立 Graphics 物件,並將點陣列的位址傳遞至 DrawCurve 方法。

繪製鐘形基本曲線

  • 下列範例繪製通過五個指定點的鐘形基本曲線。下圖顯示的是曲線和五個點。

    基本曲線

Dim points As Point() = { _
   New Point(0, 100), _
   New Point(50, 80), _
   New Point(100, 20), _
   New Point(150, 80), _
   New Point(200, 100)}

Dim pen As New Pen(Color.FromArgb(255, 0, 0, 255))
e.Graphics.DrawCurve(pen, points)

Point[] points = {
   new Point(0, 100),
   new Point(50, 80),
   new Point(100, 20),
   new Point(150, 80),
   new Point(200, 100)};

Pen pen = new Pen(Color.FromArgb(255, 0, 0, 255));
e.Graphics.DrawCurve(pen, points);

繪製封閉的基本曲線

  • 請使用 Graphics 類別的 DrawClosedCurve 方法來繪製封閉的基本曲線。在封閉的基本曲線中,曲線會延伸陣列中的最後一個點,和陣列中的第一個點連接。下列範例繪製通過六個指定點的封閉基本曲線。下圖顯示的是封閉曲線和六個點。

基本曲線

Dim points As Point() = { _
   New Point(60, 60), _
   New Point(150, 80), _
   New Point(200, 40), _
   New Point(180, 120), _
   New Point(120, 100), _
   New Point(80, 160)}

Dim pen As New Pen(Color.FromArgb(255, 0, 0, 255))
e.Graphics.DrawClosedCurve(pen, points)

Point[] points = {
   new Point(60, 60),
   new Point(150, 80),
   new Point(200, 40),
   new Point(180, 120),
   new Point(120, 100),
   new Point(80, 160)};

Pen pen = new Pen(Color.FromArgb(255, 0, 0, 255));
e.Graphics.DrawClosedCurve(pen, points);

變更基本曲線的彎曲方式

  • 將伸張引數傳遞至 DrawCurve 方法,便可變更基本曲線的彎曲方式。下列範例繪製通過同一組點的三個基本曲線。下圖顯示的是三個曲線和它們的伸張值。請注意,當伸張值為 0 時,點與點之間是以直線連接。

基本曲線

Dim points As Point() = { _
   New Point(20, 50), _
   New Point(100, 10), _
   New Point(200, 100), _
   New Point(300, 50), _
   New Point(400, 80)}

Dim pen As New Pen(Color.FromArgb(255, 0, 0, 255))
e.Graphics.DrawCurve(pen, points, 0.0F)
e.Graphics.DrawCurve(pen, points, 0.6F)
e.Graphics.DrawCurve(pen, points, 1.0F)

Point[] points = {
   new Point(20, 50),
   new Point(100, 10),
   new Point(200, 100),
   new Point(300, 50),
   new Point(400, 80)};

Pen pen = new Pen(Color.FromArgb(255, 0, 0, 255));
e.Graphics.DrawCurve(pen, points, 0.0f);
e.Graphics.DrawCurve(pen, points, 0.6f);
e.Graphics.DrawCurve(pen, points, 1.0f);

編譯程式碼

上述範例是專為與 Windows Form 搭配使用而設計的,而且它們需要 PaintEventArgs e (即 Paint 事件處理常式的參數)。

請參閱

其他資源

線條、曲線和形狀

建構和繪製曲線