나는 그래픽 경로를 사용하여 panel1에 점과 선을 그려 둡니다. 다음과 같이 코드는 다음과 같습니다 Tockekoordinate
및 tockeZelena
: 코드 1073741819 (0xc0000005) '액세스 위반'으로 종료 된 프로그램
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
있습니다. 첫 번째 것은 모든 점을 포함하고 두 번째 점은 첫 번째 점의 약 30 %를 포함하며 처음에 초기화되는 pen2를 사용하여 녹색으로 페인트하려고합니다.
checkbox1이 선택되었다고 가정하면 모든 포인트를 실행하여 GetBounds
의 직사각형을 얻으므로 포인트 좌표로 패널 1의 크기를 조정할 수 있습니다.
그러면 checkbox1.checked 부분이 나타나고 응용 프로그램이 표시된 행에서 종료됩니다.
이 문제의 원인을 아는 사람이 있습니까? 또는 적어도 VS가 오류에 대한 자세한 정보를 표시하도록 설정하는 방법을 알고 있습니까?
예, 세미콜론을 제거하면 도움이되었지만 'pen2' 선언을 paint 메소드 안에 넣으면 트릭을 만들었습니다. – Romy