unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
ColorDialog1: TColorDialog;
Shape1: TShape;
Button1: TButton;
Button2: TButton;
Button3: TButton;
BitBtn1: TBitBtn;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Shape1.Shape := stRectangle;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Shape1.Shape := stRoundRect;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Shape1.Shape := stEllipse;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
try
if ColorDialog1.Execute then
Shape1.Brush.Color := ColorDialog1.Color;
except
ShowMessage('颜色面板无法开启');
end;
end;
end.
本文介绍了一个使用Delphi或相似框架创建的简单图形界面应用程序。该程序通过不同的按钮点击事件来改变界面上形状的类型(矩形、圆角矩形、椭圆)及颜色。文章详细解释了如何使用TShape组件绘制不同类型的形状,并通过调用颜色对话框来更改填充颜色。

1万+

被折叠的 条评论
为什么被折叠?



