再学 GDI+[3]: DrawRectangle - 绘制矩形

本例效果图:

再学 GDI+[3]: DrawRectangle - 绘制矩形

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 GDIPOBJ, GDIPAPI;



procedure TForm1.FormPaint(Sender: TObject);

const

  w = 100;

  h = 50;

var

  g: TGPGraphics;

  p: TGPPen;

  x,y: Single;

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;

  y := y + h /2;

  g.DrawRectangle(p, MakeRect(x, y, w, h));



  g.Free;

  p.Free;

end;



end.


 
   

你可能感兴趣的:(drawRect)