📄 unitfrmcolor.pas
字号:
unit unitFrmColor;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
ColorCombo1: TComboBox;
ColorCombo2: TComboBox;
procedure ColorCombo1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.ColorCombo1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
TempColor: TColor; // 自 画 颜 色
TempBrushColor: TColor; // 临 时 颜 色
begin
with (Control as TComboBox) do
// 在Combo 的Canvas 上 自 画
begin
TempBrushColor := Canvas.Brush.Color;
// 保 存 原 来 的 的 颜 色
Canvas.FillRect(Rect);
case Index of // 根 据Index 的 不 同,
// 定 义 不 同 自 画 的 颜 色
0: // 黑 色
TempColor := clBlack;
1: // 蓝 色
TempColor := clBlue;
2: // 蓝 绿
TempColor := clAqua;
3: // 鲜 绿
TempColor := clLime;
4: // 红 色
TempColor := clRed;
5: // 黄 色
TempColor := clyellow;
// 可 以 在 此 加 入 对 其 它 颜 色 的 响 应
end;
Canvas.Brush.Color := TempColor;
// 自 画 颜 色 矩 形
Canvas.Rectangle(Rect.Left + 4,
Rect.Top + 1,
(Rect.Right + Rect.Left) div 3,
Rect.Bottom - 1);
Canvas.Brush.Color := TempBrushColor;
// 显 示 与 颜 色 对 应 的 字 符 串
Canvas.TextOut((Rect.Left + Rect.Right) div 2,
Rect.Top + 1,
Items[Index]);
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -