*******我需要一个斜线组件,感兴趣请进来聊聊。*********(200分)

  • 主题发起人 主题发起人 天与地
  • 开始时间 开始时间

天与地

Unregistered / Unconfirmed
GUEST, unregistred user!
我需要的斜线组件实际上是一个可以任意变换角度的填充矩形,可以斜放,
不能象有些所谓的斜线组件,是先画好一个矩形,然后画对角线,实际还是一个大的矩形。
请大侠帮忙。
 
很简单。 算出矩形旋转后的各个定点坐标, 然后用polygon函数就成了
 
我是想,线作为一个组件,带有属性,带有方法。
 
这是QuickReport的斜线组件源码,你可以参考一下自己写一个吧
unit qrline1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
quickrpt;

type
TQRLineStyle = (QRLineH,QRLineV,QRLineC);

TQRLine = class(TQRPrintable)
private
FPen: TPen;
FLineStyle: TQRLineStyle;
procedure setPen(value: TPen);
procedure setLineStyle(value: TQRLineStyle);
procedure onPenChanged(Sendoer: TObject);
protected
{ Protected declarations }
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;

procedure Paint; override;
procedure Print(OfsX, OfsY : integer); override;
published
property Pen: TPen read FPen write setPen;
property LineStyle: TQRLineStyle read FLineStyle write setLineStyle;
end;

procedure Register;

implementation

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

ControlStyle := ControlStyle - [csOpaque];
FPen := TPen.Create;
FPen.OnChange := onPenChanged;
width := 100;
height := 100;
end;

destructor TQRLine.Destroy;
begin
FPen.Free;

inherited Destroy;
end;

procedure TQRLine.SetPen(Value: TPen);
begin
FPen.Assign(value);
Invalidate;
end;

procedure TQRLine.setLineStyle(value: TQRLineStyle);
begin
if FLineStyle <> value then
begin
FLineStyle := value;
Invalidate;
end;
end;

procedure TQRLine.onPenChanged(Sendoer: TObject);
begin
Invalidate;
end;

procedure TQRLine.Paint;
var
calDiff: integer;
begin
with Canvas do
begin
Pen := FPen;
calDiff := Pen.Width div 2;
MoveTo(calDiff,calDiff);
case LineStyle of
QRLineH: LineTo(width, 0 + calDiff);
QRLineV: LineTo(calDiff, Height);
QRLineC: LineTo(width, Height);
end;
end;
end;

procedure TQRLine.Print(OfsX, OfsY : integer);
var
CalcLeft,
CalcTop,
CalcRight,
CalcBottom: integer;
begin
with ParentReport.QRPrinter do
begin
Canvas.Pen := FPen;
CalcLeft := XPos(OfsX + Size.Left);
CalcTop := YPos(OfsY + Size.Top);
CalcRight := XPos(OfsX + Size.Left + Size.Width);
CalcBottom := YPos(OfsY + Size.Top + Size.Height);
with Canvas do
begin
MoveTo(CalcLeft,CalcTop);
case LineStyle of
QRLineH:
LineTo(CalcRight, CalcTop);
QRLineV:
LineTo(CalcLeft, CalcBottom);
QRLineC:
LineTo(CalcRight, CalcBottom);
end;
end;
end;
end;

procedure Register;
begin
RegisterComponents('QReport', [TQRLine]);
end;

end.

 
谢谢楼上的大侠,有成品吗?:)

 
在踢一下。
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
611
import
I
I
回复
0
查看
595
import
I
后退
顶部