⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.~pas

📁 Delphi 有很多很好的例子
💻 ~PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    procedure ComboBoxDrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.ComboBoxDrawItem(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 + -