Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: Общие вопросы > Цвет символов в ListBox


Автор: MacTep 16.3.2006, 19:51
Можно ли в ListBox написать некоторые строки не черным цветом, а каким-либо другим.
Можно пример?

Автор: _hunter 16.3.2006, 19:59
написать можно -- нужно обрабатывать OnDrawItem
пример есть в справке

Автор: MacTep 16.3.2006, 21:10
В справке нашел следующее:
Код

procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect:TRect;State: TOwnerDrawState);

var
    Bitmap: TBitmap;      { temporary variable for the item’s bitmap }
    Offset: Integer;      { text offset width }
begin
    with (Control as TListBox).Canvas do  { draw on control canvas, not on the form }
    begin
    FillRect(Rect);       { clear the rectangle }
    Offset := 2;          { provide default offset }
    Bitmap := TBitmap((Control as TListBox).Items.Objects[Index]);  { get the bitmap }
    if Bitmap <> nil then

begin
        BrushCopy(Bounds(Rect.Left + Offset, Rect.Top, Bitmap.Width, Bitmap.Height),
            Bitmap, Bounds(0, 0, Bitmap.Width, Bitmap.Height), clRed);  {render bitmap}
        Offset := Bitmap.width + 6;    { add four pixels between bitmap and text}
    end;
    TextOut(Rect.Left + Offset, Rect.Top, (Control as TListBox).Items[Index])  { display the text }
    end;
end;

Сдается мне, что это не то...

Автор: Quadr0 16.3.2006, 21:51
...

Автор: Yanis 17.3.2006, 02:09
Взято из DRKB:
Код

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;

Автор: Guedda 17.3.2006, 10:22
http://forum.vingrad.ru/index.php?showtopic=7302&view=findpost&p=43771

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)