unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
btn1: TButton;
pnl1: TPanel;
pb1: TPaintBox;
procedure btn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
cvs: TCanvas;
procedure TForm1.btn1Click(Sender: TObject);
begin
pb1.Canvas.Brush.Color := clYellow;
pb1.Canvas.FillRect(pb1.ClientRect);
cvs := TCanvas.Create;
cvs.Handle := GetDC(pnl1.Handle);
cvs.Brush.Color := clBlue;
cvs.FillRect(pnl1.ClientRect);
cvs.Free;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Canvas.Pen.Color := clGreen;
Canvas.Pen.Width := 2;
Canvas.Brush.Color := clWhite;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
btn1: TButton;
btn2: TButton;
procedure btn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
var
pts: array[0..3] of TPoint;
begin
pts[0].X := btn1.Left+btn1.Width div 2;
pts[0].Y := 10;
pts[1].X := btn1.Left;
pts[1].Y := 100;
pts[2].X := btn1.Left+btn1.Width div 2;
pts[2].Y := 200;
pts[3].X := btn1.Left+btn1.Width;
pts[3].Y := 100;
Canvas.Polygon(pts);
end;
procedure TForm1.btn2Click(Sender: TObject);
var
pts: array[0..3] of TPoint;
begin
pts[0].X := btn2.Left+btn2.Width div 2;
pts[0].Y := 10;
pts[1].X := btn2.Left;
pts[1].Y := 100;
pts[2].X := btn2.Left+btn2.Width div 2;
pts[2].Y := 200;
pts[3].X := btn2.Left+btn2.Width;
pts[3].Y := 100;
Canvas.Polyline(pts);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Canvas.Pen.Color := clYellow;
Canvas.Pen.Width := 2;
Canvas.Brush.Color := clred;
end;
end.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~