Graphics.DrawLines:参数无效

ThN*_*ThN 2 graphics oxygene delphi-prism winforms

对于这个问题,我确实梳理了Stackoverflow类似的问题以获得答案.虽然他们中的很多人都很有帮助,但他们并没有解决我的问题.我的程序使用graphics.DrawLines方法在winform上绘制多边形,如下所示.

g.DrawLines(thepen,pts);
Run Code Online (Sandbox Code Playgroud)

但是不断提高,"参数无效",错误.所以,我按如下方式改变了这行代码,看它是否有任何区别.

g.DrawLines(new pen(color.Black),pts);
Run Code Online (Sandbox Code Playgroud)

再一次,它提出了同样的错误.pts是system.drawing.point的数组,thepen是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;
Run Code Online (Sandbox Code Playgroud)

任何帮助或提示或线索将不胜感激.

Lar*_*ech 5

如果你的pts数组少于2个点,它将抛出参数无效错误.

确保您的数组有足够多的点来绘制线条.