对于这个问题,我确实梳理了类似的堆栈溢出问题,以获得答案。虽然他们中的许多人很有帮助,但他们并没有解决我的问题。我的程序使用graphics.DrawLines方法在winform上绘制多边形,如下所示。
g.DrawLines(thepen,pts);但这会不断地引发“参数无效”,错误。因此,我修改了代码行如下,看看它是否有任何区别。
g.DrawLines(new pen(color.Black),pts);同样,它也会引发同样的错误。pts是system.drawing.point的数组,pts是system.drawing.pen。
如果我完全注释掉它,我的程序没有问题,它不会引起任何错误。然而,奇怪的是,在过去的3到4个月中,相同的代码都能正常工作。从昨天起,我似乎不能再工作了。
是否需要设置winform的属性设置?
更新这里是实际的绘图方法
method TMakerPoly.Draw;
var
pts: Array of point;
i:integer;
theBrush1:HatchBrush;
theBrush2:SolidBrush;
begin
if (theBrushStyle = HatchStyle.Wave) then
theBrush1 := new HatchBrush(theBrushStyle,Color.Transparent,color.Transparent)
else if (theBrushStyle = HatchStyle.ZigZag) then
thebrush2 := new SolidBrush(FillColor)
else
theBrush1 := new HatchBrush(theBrushStyle,FillColor,color.Transparent);
if (thePen.DashStyle = DashStyle.Custom) then
thepen.Color := Color.Transparent;
pts := new point[pcount];
if pcount >= 2 then
begin
if Active then
begin
for i := 0 to pcount-1 do
pts[i] := point(points[i]);
Translate(var pts,pcount);
thepen.Color := EdgeColor(thepen.Color);
fillColor := self.BackColor(FillColor);
if visible then
begin
if filled then
begin
if theBrushStyle = HatchStyle.ZigZag then
g.FillPolygon(theBrush2,pts)
else
g.FillPolygon(thebrush1,pts);
g.DrawPolygon(thepen, pts);
end
else
g.DrawLines(thePen, pts);
end;
end
else
begin
for i := 0 to pcount-1 do
pts[i] := point(points[i]);
if filled then
begin
if theBrushStyle = HatchStyle.ZigZag then
g.FillPolygon(theBrush2,pts)
else
g.FillPolygon(thebrush1,pts);
g.DrawPolygon(thepen,pts);
end
else
g.DrawLines(new Pen(color.Black),pts);
end;
end;
end;任何帮助、暗示或线索都将不胜感激。
发布于 2012-11-13 17:23:13
如果pts数组有小于2个点,它将抛出参数无效的错误。
确保数组有足够多的点来绘制线。
https://stackoverflow.com/questions/13365165
复制相似问题