bestlong 怕失憶論壇

 

 

搜索
bestlong 怕失憶論壇 論壇 Delphi QuickReport 報表元件 能畫斜線的QuickReport元件
查看: 4692|回復: 0
go

能畫斜線的QuickReport元件 [複製鏈接]

Rank: 9Rank: 9Rank: 9

1#
發表於 2010-8-25 09:18 |只看該作者 |倒序瀏覽 |打印
  1. unit QRLine;

  2. interface

  3. uses
  4.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  5.   QuickRpt;

  6. type
  7.   TQRLineStyle = (QRLineH, QRLineV, QRLineC);

  8.   TQRLine = class(TQRPrintable)
  9.   private
  10.     FPen: TPen;
  11.     FLineStyle: TQRLineStyle;
  12.     procedure setPen(value: TPen);
  13.     procedure setLineStyle(value: TQRLineStyle);
  14.     procedure onPenChanged(Sendoer: TObject);
  15.   protected
  16.     { Protected declarations }
  17.   public
  18.     constructor Create(AOwner: TComponent); override;
  19.     destructor Destroy; override;

  20.     procedure Paint; override;
  21.     procedure Print(OfsX, OfsY : integer); override;
  22.   published
  23.     property Pen: TPen read FPen write setPen;
  24.     property LineStyle: TQRLineStyle read FLineStyle write setLineStyle;
  25.   end;

  26. procedure Register;

  27. implementation

  28. constructor TQRLine.Create(AOwner: TComponent);
  29. begin
  30.   inherited Create(AOwner);

  31.   ControlStyle := ControlStyle - [csOpaque];
  32.   FPen := TPen.Create;
  33.   FPen.OnChange := onPenChanged;
  34.   width := 100;
  35.   height := 100;
  36. end;

  37. destructor TQRLine.Destroy;
  38. begin
  39.   FPen.Free;
  40.   inherited Destroy;
  41. end;

  42. procedure TQRLine.SetPen(Value: TPen);
  43. begin
  44.   FPen.Assign(value);
  45.   Invalidate;
  46. end;

  47. procedure TQRLine.setLineStyle(value: TQRLineStyle);
  48. begin
  49.   if FLineStyle <> value then
  50.   begin
  51.     FLineStyle := value;
  52.     Invalidate;
  53.   end;
  54. end;

  55. procedure TQRLine.onPenChanged(Sendoer: TObject);
  56. begin
  57.   Invalidate;
  58. end;

  59. procedure TQRLine.Paint;
  60. var
  61.   calDiff: integer;
  62. begin
  63.   with Canvas do
  64.   begin
  65.     Pen := FPen;
  66.     calDiff := Pen.Width div 2;
  67.     MoveTo(calDiff,calDiff);
  68.     case LineStyle of
  69.       QRLineH: LineTo(width, 0 + calDiff);
  70.       QRLineV: LineTo(calDiff, Height);
  71.       QRLineC: LineTo(width, Height);
  72.     end;
  73.   end;
  74. end;

  75. procedure TQRLine.Print(OfsX, OfsY : integer);
  76. var
  77.   CalcLeft,
  78.   CalcTop,
  79.   CalcRight,
  80.   CalcBottom: integer;
  81. begin
  82.   with ParentReport.QRPrinter do
  83.   begin
  84.     Canvas.Pen := FPen;
  85.     CalcLeft   := XPos(OfsX + Size.Left);
  86.     CalcTop    := YPos(OfsY + Size.Top);
  87.     CalcRight  := XPos(OfsX + Size.Left + Size.Width);
  88.     CalcBottom := YPos(OfsY + Size.Top + Size.Height);
  89.     with Canvas do
  90.     begin
  91.       MoveTo(CalcLeft,CalcTop);
  92.       case LineStyle of
  93.         QRLineH: LineTo(CalcRight, CalcTop);
  94.         QRLineV: LineTo(CalcLeft, CalcBottom);
  95.         QRLineC: LineTo(CalcRight, CalcBottom);
  96.       end;
  97.     end;
  98.   end;
  99. end;

  100. procedure Register;
  101. begin
  102.   RegisterComponents(‘QReport‘, [TQRLine]);
  103. end;

  104. end.
複製代碼
參考來源 http://www.8888i.net/dispQAInfo.php?id=567
我是雪龍
http://blog.bestlong.idv.tw
http://www.bestlong.idv.tw
‹ 上一主題|下一主題

Archiver|怕失憶論壇

GMT+8, 2024-4-20 14:12 , Processed in 0.010113 second(s), 11 queries .

Powered by Discuz! X1.5

© 2001-2010 Comsenz Inc.