TGPHatchBrush.Create(
hatchStyle: THatchStyle; {陰影樣式, 見下表}
foreColor: TGPColor; {前景色}
backColor: TGPColor = aclBlack {背景色, 是可選值, 默認是黑色}
);
本例效果圖:
代碼文件:unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
ColorBox1: TColorBox;
ColorBox2: TColorBox;
ComboBox1: TComboBox;
procedure FormCreate(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure ColorBox1Change(Sender: TObject);
procedure ColorBox2Change(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses GDIPOBJ, GDIPAPI, TypInfo;
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
begin
{把畫刷樣式枚舉 HatchStyle 中的所有項添加到列表}
for i := 0 to Integer(HatchStyleTotal) - 1 do
ComboBox1.Items.Add(GetEnumName(TypeInfo(HatchStyle), i));
{給三個列表初始值}
ComboBox1.ItemIndex := 0;
ColorBox1.ItemIndex := 16;
ColorBox2.ItemIndex := 3;
end;
procedure TForm1.FormPaint(Sender: TObject);
var
g: TGPGraphics;
r: TGPRect;
hb: TGPHatchBrush;
fColor,bColor: TGPColor;
hbStyle: HatchStyle;
begin
g := TGPGraphics.Create(Canvas.Handle);
g.Clear(MakeColor(255,255,255));
r := MakeRect(20, 60, ClientWidth - 40, ClientHeight - 70);
hbStyle := HatchStyle(ComboBox1.ItemIndex); {列表的序號和對應的枚舉值是一樣的}
fColor := ColorRefToARGB(ColorBox1.Selected); {前景色}
bColor := ColorRefToARGB(ColorBox2.Selected); {背景色}
{建立樣式畫刷}
hb := TGPHatchBrush.Create(hbStyle, fColor, bColor);
g.FillEllipse(hb, r);
hb.Free;
g.Free;
end;
procedure TForm1.ColorBox1Change(Sender: TObject);
begin
Repaint;
end;
procedure TForm1.ColorBox2Change(Sender: TObject);
begin
Repaint;
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
Repaint;
end;
end.