用delphi写一个颜色选择对话框程序
时间: 2023-08-28 15:05:07 浏览: 57
以下是一个简单的 Delphi 程序,用于创建颜色选择对话框:
```delphi
unit ColorDialog;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
ColorDialog1: TColorDialog;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if ColorDialog1.Execute then
Form1.Color := ColorDialog1.Color;
end;
end.
```
在此示例中,我们使用了 `TColorDialog` 组件来打开颜色选择对话框。当用户选择一种颜色并单击“确定”按钮时,程序将使用所选颜色更改窗口的背景色。