关键是设置TColorBox的Style,关键是cbCustomColor,就可以自定义了,看我的窗体文件和代码
object Form1: TForm1
Left = 192
Top = 107
Width = 286
Height = 208
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object ColorBox1: TColorBox
Left = 64
Top = 60
Width = 145
Height = 22
Style = [cbStandardColors, cbExtendedColors, cbSystemColors, cbCustomColor]
ItemHeight = 16
TabOrder = 0
OnChange = ColorBox1Change
end
end
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
ColorBox1: TColorBox;
procedure ColorBox1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ColorBox1Change(Sender: TObject);
begin
Form1.Color := ColorBox1.Selected;
end;
end.