我做了一个化斜线的控件,重载paint方法。

解决方案 »

  1.   

    unit MyQRShape;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      QuickRpt, Qrctrls;type
      Tlines=(None,TopBottom,BottomTop);
    type
      TMyQRShape = class(TQRShape)
      private
        { Private declarations }
        FLineType:Tlines ;
        procedure SetFLineType(Value:Tlines) ;
      protected
        { Protected declarations }
        procedure Paint ;override;
        procedure Print(OfsX,OfsY : Integer);override;
      public
        { Public declarations }
      published
        { Published declarations }
        property LineType:Tlines Read FLineType Write SetFLineType ;
      end;procedure Register;implementationprocedure Register;
    begin
      RegisterComponents('MyOwner', [TMyQRShape]);
    end;{ TMyQRShape }procedure TMyQRShape.Paint;
    begin
     case LineType of
     BottomTop:
     begin
      Canvas.MoveTo(0,Height) ;
      Canvas.LineTo(width,0 ) ;
     end ;
     TopBottom:
     begin
      Canvas.MoveTo(0,0) ;
      Canvas.LineTo(width,Height ) ;
     end ;
     None:
     begin
      Height := Parent.Height ;
      Top:=0 ;
      Width:=4 ;
      Shape:=qrsVertLine ;
      Inherited Paint ;
     end ;
    end ;
    end;procedure TMyQRShape.Print(OfsX, OfsY: Integer);
    begin
     with QRPrinter do
     begin
      case LineType of
      BottomTop:
        begin
         Canvas.MoveTo(Xpos(OfsX + Size.Left), Ypos(OfsY + Size.Top)+Height) ;
         Canvas.LineTo(Xpos(OfsX + Size.Left)+width,Ypos(OfsY + Size.Top) ) ;
        end ;
      TopBottom:
        begin
         Canvas.MoveTo(Xpos(OfsX + Size.Left), Ypos(OfsY + Size.Top)) ;
         Canvas.LineTo(Xpos(OfsX + Size.Left)+Width,Ypos(OfsY + Size.Top)+Height ) ;
        end ;
      None:
        Inherited Print(OfsX,OfsY ) ;
      end ;
     end ;end;procedure TMyQRShape.SetFLineType(Value:Tlines);
    begin
     if Value<>FLineType then
     begin
      FLineType:=Value ;
      Invalidate ;
     end ;
    end;end.