Reply To: RzTabbedListbox and lbOwnerDrawFixed

#2900
Ray Konopka
Keymaster

    Hi Peter,

    The TRzTabbedListBox (well, the TRzCustomTabbedListBox) uses the TabbedTextOut method to display the tabbed contents of the list box. However, if you simply want to change the color of the text of a list box item, you can called the DefaultDrawItem method in the OnDrawItem event handler. For example,

    procedure TForm7.RzTabbedListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
    begin
      if not ( odSelected in State ) then
      begin
        if Index mod 2 = 0 then
          RzTabbedListBox1.Canvas.Font.Color := clRed
        else
          RzTabbedListBox1.Canvas.Font.Color := clBlue;
      end;
      RzTabbedListBox1.DefaultDrawItem( Index, Rect, State );
    end;

    This event handler colors the lines alternating colors. Since Index starts off at 0 for the listbox, the first item is colored red. The second is blue, and the third is back to red, etc. However, if the item is selected, then the font color is not changed so that the selected font color is used against the selection background color.

    Ray