Тема: ListBox
Показать сообщение отдельно
  #2  
Старый 22.03.2007, 15:53
Аватар для 4kusNick
4kusNick 4kusNick вне форума
Местный
 
Регистрация: 06.09.2006
Адрес: Россия, Санкт-Петербург
Сообщения: 444
Репутация: 550
По умолчанию

Это пример изменения цветов строк
Код:
 
procedure TTest.ListBox1DrawItem(Control: TWinControl;
  Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin
  with (Control as TListBox).Canvas do
  begin
    case Index of
      0:
        begin
          Font.Color := clBlue;
          Brush.Color := clYellow;
        end;
      1:
        begin
          Font.Color := clRed;
          Brush.Color := clLime;
        end;
      2:
        begin
          Font.Color := clGreen;
          Brush.Color := clFuchsia;
        end;
    end;
    FillRect(Rect);
    TextOut(Rect.Left, Rect.Top, (Control as TListBox).Items[Index]);
  end;
end;

Можно менять и стиль шрифта, используя Font.Style:
Код:
 
procedure TTest.ListBox1DrawItem(Control: TWinControl;
  Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin
  with (Control as TListBox).Canvas do
  begin
    case Index of
      0:
        begin
          Font.Style := fsBold;
          Brush.Color := clYellow;
        end;
      1:
        begin
          Font.Style := fsItalic;
          Brush.Color := clLime;
        end;
      2:
        begin
          Font.Style := fsUnderline;
          Brush.Color := clFuchsia;
        end;
    end;
    FillRect(Rect);
    TextOut(Rect.Left, Rect.Top, (Control as TListBox).Items[Index]);
  end;
end;
__________________
THE CRACKER IS OUT THERE
Ответить с цитированием