1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| //Variante pour passer en couleur l'Item d'un ListBox sélectionné :
var iSelection : integer;
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin ListBox1.Style:=(lbOwnerDrawFixed);
with ListBox1.Canvas do
begin Font.Color:=clBlack; // Couleur de fonte
if Index=iSelection
then Brush.Color:=clAqua // Couleur d'arrière plan
else Brush.Color:=clWhite; // alternée bleu/blanc
FillRect(Rect); // Remplit Rect(Index) du canvas avec Brush.color
TextOut(Rect.Left, Rect.Top, ListBox1.Items[Index]); // Texte de l'Item
end;
Button1.SetFocus; //pour éliminer le pointillé
end;
procedure TForm1.ListBox1Click(Sender: TObject);
var i:integer;
begin ListBox1.MultiSelect:=false;
iSelection:=ListBox1.ItemIndex; //: sauve la valeur de l'Index sélectionné
for i:=0 to ListBox1.Items.Count-1
do ListBox1DrawItem(ListBox1,i,ListBox1.ItemRect(i),[odChecked]);
ListBox1.reFresh;
end; |
Partager