cs_Kenavo
Messages postés
702
Date d'inscription
vendredi 21 mars 2003
Statut
Membre
Dernière intervention
1 octobre 2009
5
15 avril 2004 à 16:30
Salut,
Il faut utiliser l'évènement OnDrawItem du TCombobox :
Const
TabColor : array [0..17] of TColor = (clBlack, clMaroon, clGreen, clOlive,
clNavy, clPurple, clTeal, clGray,
clSilver, clRed, clLime, clYellow,
clBlue, clFuchsia, clAqua, clLtGray,
clDkGray, clWhite);
procedure TForm1.FormCreate(Sender: TObject);
begin
Combobox1.Style := csOwnerDrawFixed;
Combobox1.ItemIndex := 0;
Combobox1.ItemHeight := 16;
end;
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin
With Combobox1.Canvas do
begin
// Couleur de fond
if (odSelected in State) then
Brush.Color := clHighlight
else
Brush.Color := Combobox1.Color;
Pen.Color := Brush.Color;
// Fond
Rectangle(Rect.Left,Rect.Top,Rect.Right,Rect.Bottom);
// Texte
TextOut(Rect.Left+18,Rect.top+2,Combobox1.Items[Index]);
// Choix du pavé de couleur en fonction de l'index
Brush.Color := TabColor[Index];
Pen.Color := Brush.Color;
// Dessin du pavé
Rectangle Rect.Left+2,Rect.Top+2,Rect.Left+14,Rect.Top+14);
end;
end;
Kénavo
Code, Code, Codec !