Вывод : Сегодня я изучил свойства компонента TStringGrid. Написал программу с использованием массивов.
Практическая работа №24
Тема практической работы: Класс TPen. Класс TBrush.
Цель практической работы: Научится использовать классы TPen, TBrush.
Ход работы :
Задание №1
Рис 98
Листинг :
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs;
type
TForm1 = class(TForm)
procedure FormResize(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormResize(Sender: TObject);
var w,h,wm,hm:integer;
begin
form1.Refresh;
wm:=form1.ClientWidth; w:=wm div 8;
hm:=form1.ClientHeight; h:=hm div 10;
with form1.Canvas do begin
brush.Color:=clBlue;
brush.Style:=bsDiagCross;
pen.color:=clblue;
rectangle(0,0,wm,h);
brush.Color:=clGreen;
brush.Style:=bsHorizontal;
pen.color:=clGreen;
rectangle(0,hm-h,wm,hm);
brush.Color:=clYellow;
brush.Style:=bsSolid;
pen.color:=clYellow;
ellipse(w,2*h,2*w,2*h+w);
brush.Color:=clGray;
brush.Style:=bsSolid;
pen.color:=clMaroon;
rectangle(2*w,hm-5*h,6*w,hm-h);
polygon([point(2*w,hm-5*h),point(4*w,hm-7*h),
point(6*w,hm-5*h),point(2*w,hm-5*h)]);
brush.Color:=clwhite;
brush.Style:=bsSolid;
pen.color:=clMaroon;
rectangle(3*w,hm-4*h,5*w,hm-2*h);
end;
end;
end.
Задание №2
Рис 99
Листинг :
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.Buttons;
type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
PaintBox1: TPaintBox;
procedure PaintBox1Paint(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
with canvas do begin
pen.Color:=clred;
brush.Color:=clred;
ellipse(70,40,130,100);
sleep(500);
pen.Color:=clmaroon;
brush.Color:=clmaroon;
ellipse(70,40,130,100);
pen.Color:=clYellow;
brush.Color:=clYellow;
ellipse(70,110,130,170);
sleep(500);
pen.Color:=clolive;
brush.Color:=clolive;
ellipse(70,110,130,170);
pen.Color:=cllime;
brush.Color:=cllime;
ellipse(70,180,130,240);
sleep(500);
pen.Color:=clbackground;
brush.Color:=clbackground;
ellipse(70,180,130,240);
pen.Color:=clYellow;
brush.Color:=clYellow;
ellipse(70,110,130,170);
sleep(500);
pen.Color:=clolive;
brush.Color:=clolive;
ellipse(70,110,130,170);
pen.Color:=clred;
brush.Color:=clred;
ellipse(70,40,130,100);
sleep(500);
pen.Color:=clmaroon;
brush.Color:=clmaroon;
ellipse(70,40,130,100);
end;
end;
procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
with canvas do begin
pen.Color:=clBlack;
brush.color:=clblack;
rectangle(50,30,150,250);
pen.color:=clgray;
brush.color:=clgray;
rectangle(90,250,110,330);
pen.color:=clmaroon;
brush.color:=clmaroon;
ellipse(70,40,130,100);
pen.Color:=clolive;
brush.color:=clolive;
ellipse(70,110,130,170);
pen.Color:=clbackground;
brush.color:=clbackground;
ellipse(70,180,130,240);
end;
end;
end.
Задание №3
Рис 100
Листинг :
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls;
type
TForm1 = class(TForm)
PaintBox1: TPaintBox;
procedure PaintBox1Paint(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.PaintBox1Paint(Sender: TObject);
var x,y:integer;
begin
with PaintBox1.Canvas do
begin
brush.Color:=clRed;
ellipse(0,0, PaintBox1.width, PaintBox1.height);
font.Name:='arial';
font.Size:=height div 5;
font.Style:=[fsBold,fsItalic];
font.Color:=clwhite;
x:=( PaintBox1.width-textwidth('Delphi')) div 2;
y:=( PaintBox1.height-textheight('D'))div 2;
textout(x,y,'Delphi');
end;
end;
end.
Вывод : Сегодня я научился использовать классы TPen, TBrush.
Достарыңызбен бөлісу: |