我正在创建一个基于文档的应用程序,我想要绘制一个在文本基础上的水平线。但是,直线不应该是直线的。我想画一条这样的线。

目前,我正在使用System.Graphics对象绘制任何对象。
private void DrawLine(Graphics g, Point Location, int iWidth)
{
iWidth = Convert.ToInt16(iWidth / 2);
iWidth = iWidth * 2;
Point[] pArray = new Point[Convert.ToInt16(iWidth / 2)];
int iNag = 2;
for (int i = 0; i < iWidth; i+=2)
{
pArray[(i / 2)] = new Point(Location.X + i , Location.Y + iNag);
if (iNag == 0)
iNag = 2;
else
iNag = 0;
}
g.DrawLines(Pens.Black, pArray);
}更新
以上代码工作良好,线条绘制完美,但是,这段代码会影响应用程序的性能。还有别的办法做这件事吗。
发布于 2014-02-18 16:52:34
如果您想要快速绘图,只需绘制您想要的线条的png图像,宽度大于所需的宽度,然后绘制图像:
private void DrawLine(Graphics g, Point Location, int iWidth)
{
Rectangle srcRect = new Rectangle(0, 0, iWidth, zigzagLine.Height);
Rectangle dstRect = new Rectangle(Location.X, Location.Y, iWidth, zigzagLine.Height);
g.DrawImage(zigzagLine, dstRect, srcRect, GraphicsUnit.Pixel);
}zigzagLine是位图。
瓦尔特
https://stackoverflow.com/questions/21845302
复制相似问题