我做的东西,需要用Canvas画线,但是得绕过一些可视控件,就像电路图一样,不定的
两个管脚画线要绕过其他集成块,又不能给每一个都编一个固定的函数,灵活性太差。
请大家帮帮我,谢谢 !

解决方案 »

  1.   

    你在控件的Parent上画,是画不到控件上去的
      

  2.   

    用一个数组存储控件的位置信息
    然后自定义一个判断的函数
    每画一根线的时候,调用判断,根据返回值处理
    1.直线
    2.绕一下,无非就是加了三条直线,或者可以直接polyline(是不是这个函数?)
      

  3.   

    Function TForm1.CheckLine(x1, y1, x2, y2: Integer):Boolean;
    var
      k : double;
    begin
      //循环检测,是否遮挡
      //根据直线的斜率,分为两种情况:有斜率,无斜率,分别处理
      if x1 = x2 then  //无斜率
      begin
        if ((y1<PosArray[1].Top)and(y2>PosArray[1].Bottom))
           or  ((y2<PosArray[1].Top)and(y1>PosArray[1].Bottom)) then
        begin
          Result := True;
          zhedangPoint[iCount].X := x1;
          zhedangPoint[iCount].Y := PosArray[1].Top;
          Inc(iCount);
          zhedangPoint[iCount].X := x1;
          zhedangPoint[iCount].Y := PosArray[1].Bottom ;
          Inc(iCount);
        end
        else
        result := False;
      end
      else   //有斜率
      begin
        if y1 = y2 then //水平,少一个判断
        begin
          if ((x1<PosArray[1].Left)and(x2>PosArray[1].Right))
           or  ((x2<PosArray[1].Left)and(x1>PosArray[1].Right)) then
          begin
            Result := True;
            zhedangPoint[iCount].X := PosArray[1].Left;
            zhedangPoint[iCount].Y := y1;
            Inc(iCount);
            zhedangPoint[iCount].X := PosArray[1].Right;
            zhedangPoint[iCount].Y := y1;
            Inc(iCount);
          end
          else
            Result := False;
        end
        else  //任意
        begin
          k := (y1-y2) / (x1-x2);
          if (True) then
          ;//分别判断四条线的情况,代码太多不写了
        end;
      end;
    end;自己完善吧,不断实验
      

  4.   

    怎么检测Form中所有的控件呢?并且动态的给
    TPosition = Record
        Left : integer;
        Top : integer;
        Right : integer;
        Bottom : integer;
      end;
     private
        { Private declarations }
        PosArray : Array [1..20] of TPosition;
        zhedangPoint : Array [1..20] of TPoint;赋值,这个偶不会,不写了,我要吃饭了。