Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

TListBox

Posted on 2002-04-28
3
Medium Priority
?
283 Views
Last Modified: 2010-04-04
How do i make each line of a TListBox different Colors?

Line1 < Red
Line 2 < Green?

or Line 3 < Blue and so on, is it possible?


- Thanks.


Craig C.
0
Comment
Question by:craig_capel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 280 total points
ID: 6975258
hi,
set it to lbOwnerDrawFixed and on the DrawItem event:

procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  with TListBox(Control) do begin
    case Index mod 4 of
      0: Canvas.Brush.Color := clRed;
      1: Canvas.Brush.Color := clSilver;
      2: Canvas.Brush.Color := clBlue;
      3: Canvas.Brush.Color := clYellow;
//      etc.. or use some loop
    end;
    case Index mod 4 of
      0: Canvas.Font.Color := clWhite;
      1: Canvas.Font.Color := clRed;
      2: Canvas.Font.Color := clWhite;
      3: Canvas.Font.Color := clNavy;
    end;
    Canvas.TextRect(Rect, Rect.Left, Rect.Top, Items.Strings[Index]);
  end;
0
 
LVL 17

Expert Comment

by:inthe
ID: 6975345
btw if you dont want to use specific colors or an aray you can make it random or something, ie:

Drawitem event :

var
 i,j : integer;
  begin
  randomize;
  j := random(6555536);
  with TListBox(Control) do begin
  for i := 0 to TListBox(Control).Items.Count -1 do begin
      Canvas.Brush.Color := j;
  etc..
0
 
LVL 2

Author Comment

by:craig_capel
ID: 6982867
Thanks - sorry for the long delay - thanks :)

The Index confused me for a while, Index can not be accessed unless you do With Object Do (For Tlistbox)
but i had a hard time just making the 3rd or 4th box change color, because in your routine, you add then indext gets incremented correct? oh well - you get the points thanks :)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question