Тема: ListBox
Показать сообщение отдельно
  #3  
Старый 02.08.2012, 21:36
Аватар для Alegun
Alegun Alegun вне форума
LMD-DML
 
Регистрация: 12.07.2009
Адрес: Богородское
Сообщения: 3,025
Версия Delphi: D7E
Репутация: 1834
По умолчанию

Пример из DRKB. Необходимо изменить свойство Style в TListBox на lbOwnerDrawFixed, иначе событие OnDrawItem никогда не произойдёт. Обработчик события OnDrawItem TListBox:
Код:
 
procedure TForm1.ListBox1DrawItem (Control: TWinControl; Index: Integer;Rect: TRect; State: TOwnerDrawState);

var
   myColor: TColor;
   myBrush: TBrush;      

begin
myBrush := TBrush.Create;  
with (Control as TListBox).Canvas do
begin
   if not Odd(Index) then  myColor := clSilver
   else myColor := clYellow;

   myBrush.Style := bsSolid; 
   myBrush.Color := myColor; 
   Windows.FillRect(handle, Rect, myBrush.Handle); 
   Brush.Style := bsClear;  
   TextOut(Rect.Left, Rect.Top,(Control as TListBox).Items[Index]);  
   MyBrush.Free;

end;

end;

или:

Код:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; 

Rect: TRect; State: TOwnerDrawState); 

begin 
With ListBox1 do begin 

 If odSelected in State then 
 Canvas.Brush.Color:=clTeal { твой цвет } 
 else 
 Canvas.Brush.Color:=clWindow; 
 Canvas.FillRect(Rect); 
 Canvas.TextOut(Rect.Left+2,Rect.Top,Items[Index]); 
end; 

end;

С ListBox1.ItemIndex:= ListBox1.Count - 1 полностью согласен.
Ответить с цитированием