绘图报错,读取或写入受保护的内存,该如何解决?
报错如下图所示贴出代码如下:
public void paint(Graphics g)
{
GraphicsPath path = new GraphicsPath();
Rectangle rectangle = new Rectangle(pt, new Size(recWidth, recHeight));
Rectangle toggleNode = Rectangle.Empty; //the [+] [-]
switch (this.shapeType)
{
case ShapeTypes.Rectangle:
path = new GraphicsPath();
path.AddRectangle(rectangle);
break;
case ShapeTypes.SM:
path = new GraphicsPath();
path.AddEllipse(rectangle);
break;
case ShapeTypes.Ellipse:
path = new GraphicsPath();
path.AddEllipse(rectangle);
break;
}
Region region = new Region(path);
g.FillRegion(new SolidBrush(fillColor), region);
if (frameWidth == 0)
g.FillRectangle(Brushes.White, new Rectangle(pt.X, pt.Y, recWidth + 2, recHeight + 2));
else
g.FillRectangle(Brushes.White, new Rectangle(pt.X, pt.Y, recWidth + frameWidth, recHeight + frameWidth));
ama:
try
{
g.FillPath(new SolidBrush(fillColor), path);
if (frameWidth != 0)
{
if (!isRuanSheng)
{
Pen mypen = new Pen(frameColor, frameWidth);
g.DrawPath(mypen, path);
}
else
{
Pen mypen = new Pen(Color.FromArgb(frameColor.A/2,frameColor.G/2,frameColor.B/2), frameWidth+1);
g.DrawPath(mypen, path);
}
}
}
catch (AccessViolationException ex)
{
goto ama;
}
if (isHovered)
{
g.DrawPath(new Pen(Color.Blue,frameWidth), path);
g.DrawRectangle(new Pen(Color.Blue, frameWidth), ReSizeRec);
}
if (isSelected)
{
g.DrawPath(new Pen(Color.Green, frameWidth), path);
g.DrawRectangle(new Pen(Color.Green, frameWidth), ReSizeRec);
g.DrawRectangle(new Pen(Color.Green, frameWidth), ConRec);
}
if (relatedImage == null)
{
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
Brush brush = new SolidBrush(this.fontColor);
g.DrawString(text, font, brush, rectangle, sf);
}
else
{
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
Brush brush = new SolidBrush(this.fontColor);
//Rectangle rec1 = new Rectangle();
//rec1.Location = rectangle.Location;
//rec1.Width = rectangle.Width * 3 / 4;
//rec1.Height = rectangle.Height;
Rectangle rec2 = new Rectangle();
rec2.Location = new Point(pt.X+ rectangle.Width * 3 / 4 + 1, pt.Y+rectangle.Height/4);
rec2.Width = rectangle.Width / 4 - 1;
rec2.Height = rectangle.Height/2;
Rectangle rec1 = new Rectangle();
//rec1.Location = rectangle.Location;
rec1.Location = new Point(pt.X+recWidth/4,pt.Y+recHeight/4);
rec1.Width = recWidth / 2;
rec1.Height = recHeight / 2;
//g.DrawString(text, font, brush, rectangle, sf);
g.DrawString(text, font, brush, rec2, sf);
//g.DrawImage(relatedImage, rec1);
g.DrawImage(relatedImage, rec1);
}
}
求高手帮忙 c#; graphics fillpath
补充:.NET技术 , C#