IGPSolidBrush(实心画刷)只是在 IGPBrush 的基础上增加了一个可读写的 IGPSolidBrush.Color 属性.
IGPHatchBrush(阴影画刷)有三个只读属性: 阴影样式、前景色、背景色; 它们也刚好是 Create 方法的参数.
Create 也可只有前两个参数, 此时背景色默认为不透明的黑色.
下面的例子展示了阴影画刷的所有阴影样式, 效果图如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure FormPaint(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses GdiPlus;
procedure TForm1.FormPaint(Sender: TObject);
var
Graphics: IGPGraphics;
Brush: IGPHatchBrush;
ForeColor, BackColor: TGPColor;
Rect: TGPRect;
i: Integer;
begin
Graphics := TGPGraphics.Create(Handle);
Rect.Initialize(10, 10, 100, 60);
ForeColor := $FFFF0000;
BackColor := $FFFFFF00;
Graphics.Clear($FFFFFFFF);
for i := 0 to 52 do
begin
Brush := TGPHatchBrush.Create(TGPHatchStyle(i), ForeColor, BackColor);
Graphics.FillRectangle(Brush, Rect);
Graphics.DrawString(IntToStr(i),
TGPFont.Create(Canvas.Handle),
TGPPointF.Create(0, 0),
TGPSolidBrush.Create($FF000000));
Graphics.TranslateTransform(0, Rect.Height * 1.2);
if Graphics.Transform.OffsetY > ClientHeight - Rect.Height - Rect.Y then
begin
Graphics.TranslateTransform(Rect.X * 1.5 + Rect.Width, -Graphics.Transform.OffsetY);
end;
end;
end;
end.