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.