首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Graphics.DrawLines :参数无效

Graphics.DrawLines :参数无效
EN

Stack Overflow用户
提问于 2012-11-13 16:59:41
回答 1查看 2.3K关注 0票数 2

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

代码语言:javascript
复制
g.DrawLines(thepen,pts);

但这会不断地引发“参数无效”,错误。因此,我修改了代码行如下,看看它是否有任何区别。

代码语言:javascript
复制
g.DrawLines(new pen(color.Black),pts);

同样,它也会引发同样的错误。pts是system.drawing.point的数组,pts是system.drawing.pen。

如果我完全注释掉它,我的程序没有问题,它不会引起任何错误。然而,奇怪的是,在过去的3到4个月中,相同的代码都能正常工作。从昨天起,我似乎不能再工作了。

是否需要设置winform的属性设置?

更新这里是实际的绘图方法

代码语言:javascript
复制
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;

任何帮助、暗示或线索都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-13 17:23:13

如果pts数组有小于2个点,它将抛出参数无效的错误。

确保数组有足够多的点来绘制线。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13365165

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档