看来,这是一个已知的bug ......
下面的代码似乎功能与你的要求:
protected override void OnPaint(PaintEventArgs e)
{
PointF[] points = new PointF[] { new PointF(73.36f, 196),
new PointF(75.44f, 32),
new PointF(77.52f, 32),
new PointF(79.6f, 196),
new PointF(85.84f, 196) };
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
Rectangle b = new Rectangle(70, 32, 20, 165);
e.Graphics.SetClip(b);
e.Graphics.DrawLines(Pens.Red, points); // clipped incorrectly
e.Graphics.TranslateTransform(80, 0);
e.Graphics.ResetClip();
e.Graphics.DrawLines(Pens.Red, points);
}
注:我已经AntiAlias'ed线和扩展您的裁剪区域1
看来,以下变通可能帮助(虽然未测试):
- 笔是多于一个像素厚
- 该生产线是完全水平或垂直
- 的修剪是针对窗口边界,而不是一个剪裁矩形
以下是文章的列表可能/或然后再可能无法帮助:
http://www.tech-archive.net/pdf/Archive/Development/microsoft.public.win32.programmer.gdi/2004-08/0350.pdf http://www.tech-archive.net/Archive/Development/microsoft.public.win32.programmer.gdi/2004-08/0368.html
OR ...
以下也是可能的:
protected override void OnPaint (PaintEventArgs e)
{
PointF[] points = new PointF[] { new PointF(73.36f, 196),
new PointF(75.44f, 32),
new PointF(77.52f, 32),
new PointF(79.6f, 196),
new PointF(85.84f, 196) };
Rectangle b = new Rectangle(70, 32, 20, 164);
Region reg = new Region(b);
e.Graphics.SetClip(reg, System.Drawing.Drawing2D.CombineMode.Union);
e.Graphics.DrawLines(Pens.Red, points); // clipped incorrectly
e.Graphics.TranslateTransform(80, 0);
e.Graphics.ResetClip();
e.Graphics.DrawLines(Pens.Red, points);
}
使用组合的/与画布/控制的ClientRectangle的区域联合在一起(我认为)这effecivly剪辑。由于区域与矩形不同,结果应该是预期的。此代码可以通过在调用setClip()之后添加
e.Graphics.FillRectangle(new SolidBrush(Color.Black), b);
来工作。这清楚地显示了只出现在剪辑区域中的黑色矩形。
这可能是一个有效的解决方法,如果反锯齿行不是一个选项。
希望这会有所帮助