本例效果图:

//在GDI+中,绘制矩形是通过TGPGraphics类的DrawRectangle方法实现的unit Unit1;interfaceuses 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 GDIPOBJ, GDIPAPI;procedure TForm1.FormPaint(Sender: TObject);const w = 100; h = 50;var g: TGPGraphics; p: TGPPen; x,y: Single; //32位单精度浮点型变量begin g := TGPGraphics.Create(Canvas.Handle); p := TGPPen.Create(0, 2); g.Clear(MakeColor(255,255,255)); x := 20; y := 20; p.SetColor(aclRed); //设置画笔颜色为红色 g.DrawRectangle(p, x, y, w, h); //画一个矩形 p.SetColor(aclGold); //设置画笔颜色为黄色 x := x + w / 2; {70} y := y + h /2; {45} g.DrawRectangle(p, MakeRect(x, y, w, h)); //画另一个矩形 g.Free; p.Free;end;end. |
浙公网安备 33010602011771号