//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
const TColor CColors[5] = {clBlack, clWhite, clRed, clBlue, clGreen};
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
//一定在设置上记得:
// style = csOwnerDrawFixed
void __fastcall TForm1::ComboBox1DrawItem(TWinControl *Control, int Index,
TRect &Rect, TOwnerDrawState State)
{
((TComboBox *)Control)->Canvas->FillRect(Rect);
switch(Index)
{
case 0:
//((ComboBox1 *)Control)->Canvas->Pen->Color = clBlack;
//((ComboBox1 *)Control)->Canvas->FillRect(Rect);
//((ComboBox1 *)Control)->Canvas->Rectangle(Rect.left, Rect.top, Rect.right,Rect.bottom);
((TComboBox *)Control)->Canvas->Font->Color = clRed;
break;
case 1:((TComboBox *)Control)->Canvas->Font->Color = clRed;
break;
case 2:((TComboBox *)Control)->Canvas->Font->Color = clRed;
break;
case 3: ((TComboBox *)Control)->Canvas->Font->Color = clBlue;
break;
case 4:((TComboBox *)Control)->Canvas->Font->Color = clGreen;
break; //(Pchar)(ComboBox1->Items->Strings[Index])
}
//DrawText(ComboBox1->Canvas->Handle,(StrToInt)(ComboBox1->Items->Strings[Index]),-1,&Rect, DT_CENTER);
((TComboBox *)Control)->Canvas->TextOutA(Rect.left+3, Rect.top, (ComboBox1->Items->Strings[Index]));
}
//---------------------------------------------------------------------------