一行代码设置颜色的控件

本例效果图:

一行代码设置颜色的控件
提示: 新建工程后, 添加 TColorBox、TColorListBox、TColorGrid、TButtonColor 四个控件, 分别双击它们建立默认事件, 然后贴入下面代码:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ColorGrd, StdCtrls, TeCanvas, ExtCtrls;

type
  TForm1 = class(TForm)
    ColorBox1: TColorBox;
    ColorListBox1: TColorListBox;
    ColorGrid1: TColorGrid;
    ButtonColor1: TButtonColor;
    procedure ColorListBox1Click(Sender: TObject);
    procedure ColorBox1Change(Sender: TObject);
    procedure ColorGrid1Change(Sender: TObject);
    procedure ButtonColor1Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ColorListBox1Click(Sender: TObject);
begin
  Self.Color := ColorListBox1.Selected;
end;

procedure TForm1.ColorBox1Change(Sender: TObject);
begin
  Self.Color := ColorBox1.Selected;
end;

procedure TForm1.ColorGrid1Change(Sender: TObject);
begin
  Self.Color := ColorGrid1.ForegroundColor;
end;

procedure TForm1.ButtonColor1Click(Sender: TObject);
begin
  Self.Color := ButtonColor1.SymbolColor;
end;

end.

 
 
 
 
 

 

 
  

你可能感兴趣的:(一行代码设置颜色的控件)