winform绘图项目中,经常需要绘制波形图,简称贝塞尔图形.
可以使用 Graphics 的 DrawBezier 绘画.具体代码如下:
public void Draw()
{
Graphics graphics = this.CreateGraphics();
Pen pen = new Pen(Color.Black, 1);
int startx = 50;
int starty = 300;
int height = 40;
int width = 55;
Point pointX1 = new Point(startx, starty);
Point pointY1 = new Point(startx + this.Width, starty);
Point pointX2 = new Point(startx, starty - 45);
Point pointY2 = new Point(startx, starty + 45);
graphics.DrawLine(pen, pointX1, pointY1);
graphics.DrawLine(pen, pointX2, pointY2);
for (int i = 0; i < 10; i++)
{
//上部分半圆
graphics.DrawBezier(pen, startx + width * 2 * i, starty, startx + width * 2 * i + 15, starty - height, startx + width * 2 * i + 40, starty - height, startx + width + width * 2 * i, starty);
//下半部分半圆
graphics.DrawBezier(pen, startx + width + (width * 2 * i), starty, startx + width + (width * 2 * i) + 15, starty + height, startx + width + (width * 2 * i) + 40, starty + height, startx + width * 2 + (width * 2 * i), starty);
}
}
实现效果如下: