【发布时间】:2016-06-20 06:30:40
【问题描述】:
我正在使用graphicPath 在panel1 中绘制点和线。代码如下:
private void panel1_Paint_1(object sender, PaintEventArgs e)
{
Graphics G = e.Graphics;
GraphicsPath gp = new GraphicsPath();
foreach (var line in tockeKoordinate)
{
gp.AddLine((float) (line.startX), (float) (line.startY), (float) (line.endX), (float) (line.endY));
gp.CloseFigure();
}
var rect = gp.GetBounds();
var scale = Math.Min(1f * (int)(panel1.ClientSize.Width) / rect.Width,
1f * (int)(panel1.ClientSize.Height) / rect.Height);
using (Pen pen = new Pen(Color.Black, 0.0001f))
{
G.SmoothingMode = SmoothingMode.AntiAlias;
G.Clear(Color.White);
G.TranslateTransform(0, +panel1.ClientSize.Height);
G.ScaleTransform(scale, -scale);
G.TranslateTransform(-rect.X, -rect.Y);
G.DrawPath(pen, gp);
}
if(checkBox1.Checked)
{
gp.ClearMarkers();
foreach (var line2 in tockeZelene)
{
gp.AddLine((float)(line2.startX), (float)(line2.startY), (float)(line2.endX), (float)(line2.endY));
gp.CloseFigure();
}
using (pen2);
{
G.DrawPath(pen2, gp); <--- access violation here
}
}
}
基本上我有两个Lists:Tockekoordinate 和tockeZelena。第一个包含所有点,第二个包含大约 30% 的第一个点,我想使用我的 pen2 将其绘制为绿色,该笔在开始时已初始化。
假设checkbox1被选中,我运行所有点以获得矩形GetBounds,所以我可以用点坐标缩放panel1。
然后 checkbox1.checked 部分来了,应用程序在标记的行退出。
有谁知道是什么原因造成的?或者至少知道如何设置 VS 以向我显示有关所述错误的更多信息?
【问题讨论】: