在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
Delphi 绘图TCanvas类[3] TPen类参数及介绍 1、TPen(用于在画布上绘制线条或轮廓形状) 单元:Graphics TPen = class(TGraphicsObject)
private
FMode: TPenMode;
procedure GetData(var PenData: TPenData);
procedure SetData(const PenData: TPenData);
protected
function GetColor: TColor;
procedure SetColor(Value: TColor);
function GetHandle: HPen;
procedure SetHandle(Value: HPen);
procedure SetMode(Value: TPenMode);
function GetStyle: TPenStyle;
procedure SetStyle(Value: TPenStyle);
function GetWidth: Integer;
procedure SetWidth(Value: Integer);
public
constructor Create;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
property Handle: HPen read GetHandle write SetHandle;
published
property Color: TColor read GetColor write SetColor default clBlack;
property Mode: TPenMode read FMode write SetMode default pmCopy;
property Style: TPenStyle read GetStyle write SetStyle default psSolid;
property Width: Integer read GetWidth write SetWidth default 1;
end;
TPen 主要属性: Color、Width、Style、Mode 2、TPenStyle(确定画笔绘制线条的样式)
示例1:红色实线 Canvas.Pen.Color := clRed;
Canvas.Pen.Style := psSolid ;
//或:Canvas.Pen.Style := TPenStyle(0);
示例2:(在最大化的窗体上绘制许多大小和颜色各异的矩形) var
qX, qY: Integer;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
Timer1.Enabled:=not Timer1.Enabled;
if Timer1.Enabled then begin
WindowState := wsMaximized;
Timer1.Interval := 50;
Randomize;
end else begin
WindowState := wsNormal;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
qX := Random(Screen.Width - 10);
qY := Random(Screen.Height - 10);
Canvas.Pen.Color := Random(65535);
case Random(5) of
0: Canvas.Pen.Style := psSolid;
1: Canvas.Pen.Style := psDash;
2: Canvas.Pen.Style := psDot;
3: Canvas.Pen.Style := psDashDot;
4: Canvas.Pen.Style := psDashDotDot;
end;
Canvas.Rectangle(qX, qY, qX + Random(400), qY + Random(400));
end;
3、TPenMode(指示笔的颜色如何与画布的颜色交互) 单元:Graphics 或 QGraphics type TPenMode = (pmBlack, pmWhite, pmNop, pmNot, pmCopy, pmNotCopy, pmMergePenNot, pmMaskPenNot, pmMergeNotPen, pmMaskNotPen, pmMerge, pmNotMerge, pmMask, pmNotMask, pmXor, pmNotXor);
例如: Canvas.Pen.Mode := pmBlack;
//或:Canvas.Pen.Mode := TPenMode(0);
创建时间:2020.02,01 更新时间:2022.04.12 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论