Point 結構體僅支持整數座標,浮點數需使用 PointF 結構體。
using System.Drawing;
using System.Drawing.Drawing2D;
// 創建浮點座標點數組
PointF[] points = {
new PointF(x1, 0),
new PointF(x1, -y1),
new PointF(y1, x1 + Width / 4f),
new PointF(x1 + Width / 4f, 0)
};
// 繪制平滑折線
using (Pen pen = new Pen(Color.Black, 3)) {
pen.StartCap = LineCap.Round;
pen.EndCap = LineCap.Round;
pen.LineJoin = LineJoin.Round;
graphics.SmoothingMode = SmoothingMode.AntiAlias; // 抗鋸齒
graphics.DrawLines(pen, points);
}
| 類型 | 命名空間 | 座標類型 | 適用場景 |
|---|---|---|---|
| Point | System.Drawing | int X, Y | 像素級精確定位 |
| PointF | System.Drawing | float X, Y | 浮點精度、縮放變換 |
| Point (WPF) | System.Windows | double X, Y | WPF 邏輯座標 |
// Graphics 類提供完整重載
public void DrawLines(Pen pen, Point[] points); // 整數版
public void DrawLines(Pen pen, PointF[] points); // 浮點版
// 同樣適用於:
// DrawPolygon, DrawCurve, DrawBeziers, FillPolygon 等
Width / 4 → 改為 Width / 4f 或 (float)Width / 4Point p = new Point((int)x, (int)y)