为什么打开抗锯齿会干扰我的虚线笔?
(来源:googlepages.com)
我相信这是创建宽度为 0 的笔然后缩放的问题。在我看来,有两种方法可以解决这个问题:
您可以使用一些 C# 3.0 代码来完成后一种解决方法:
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
using (Pen p = new Pen(Color.Black, 0.0f))
{
p.DashStyle = DashStyle.Dash;
g.ScaleTransform(4.0f, 4.0f);
g.DrawLine(p, 5.0f, 5.0f, 55.0f, 5.0f);
g.SmoothingMode = SmoothingMode.AntiAlias;
p.DashPattern = Array.ConvertAll(p.DashPattern, d => d * 4.0f);
g.DrawLine(p, 5.0f, 10.0f, 55.0f, 10.0f);
}
base.OnPaint(e);
}