2012-11-13 6 views
2

이 문제의 경우, Stackoverflow에서 비슷한 질문을 통해 답을 찾아 냈습니다. 많은 도움이되었지만 문제를 해결하지 못했습니다. 내 프로그램은 다음과 같이 graphics.DrawLines 메서드를 사용하여 winform에 다각형을 그립니다.Graphics.DrawLines : 매개 변수가 유효하지 않습니다.

g.DrawLines(thepen,pts); 

하지만 계속해서 "매개 변수가 유효하지 않습니다"라는 오류가 발생합니다. 그래서 나는 그 코드 라인을 다음과 같이 변경하여 어떤 차이가 있는지 확인했습니다.

g.DrawLines(new pen(color.Black),pts); 

다시 동일한 오류가 발생합니다. pts는 system.drawing.point의 배열이고 thepen은 system.drawing.pen입니다.

완전히 주석 처리하면 프로그램에 오류가 발생하지 않습니다. 그러나 이상한 점은 지난 3 ~ 4 개월 동안 똑같은 코드를 사용해도 문제가 없다는 것입니다. 어제부터 다시 작동시키지 못합니다.

설정할 필요가있는 winform 속성 설정이 있습니까?

여기 UPDATE

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; 

어떤 도움이나 힌트 혹은 힌트 크게 이해할 것이다 실제 연신 방법이다.

+2

오류가 잘못된 매개 변수에 관한 것이면 변수 선언 및 매개 변수 ** 초기화로 코드를 실제로 게시해야합니다. 그들에 대한 모호한 설명은 유용하지 않습니다. –

+0

'points'와'pcount'는 어디에서 왔는가? 여러분이 게시 한 코드에서 아무 곳에 나 선언되지 않았기 때문입니다. (여기에 도움이 필요하면 도움을 줄 정보를 제공해야합니다. 제공하지 않는 외부 변수에 의존하는 막연한 설명 및 코드는 전혀 유용하지 않습니다.) –

+0

@KenWhite, 이러한 변수가 정의되어 있습니다. 동급에서. 'points'는 포인트의 arraylist이고, pcount는 arraylist의 포인트의 수입니다. – ThN

답변

5

pts 배열의 길이가 2보다 작 으면 매개 변수가 잘못되었습니다. 오류가 발생합니다.

배열에 선을 그릴 수있는 충분한 점이 있는지 확인하십시오.

+0

, 네가 맞다. 그게 내가'if (pcount> = 2) then' 블록을 검사하는 이유입니다. 나는 적어도 2 점 이상의 점수를 가져야한다는 것을 알고 있습니다. – ThN

+0

@digitalanalog 오류를 복제 할 수있는 유일한 방법입니다. 점 []이 어디에서 왔는지, 그리고 Translate() 함수에서 무엇을하고 있는지 확인합니다. – LarsTech

+0

답변 해 주셔서 감사합니다. 프로그램이 arraylist'points'에 포인트를 추가하는 중이 더라구 어떻게 든 항상 메소드를 먼저 실행했기 때문에이 오류가 발생했습니다. 그것은 arraylist가 2 점 이하임을 의미했습니다. 따라서 오류. :) – ThN