-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi Russell,
> Hi all, absolute newbie here. Welcome!! > Can I make a listbox contain different coloured text? I have a > listbox that adds words in a wordgame I am writing and would like > to show the incorrect words in red, correct words black. I googled the phrase "delphi listbox colors" and found two articles that should be of use to you. The first demonstrates adding colors to a TListBox, and the second demonstrates adding graphics. You should be able to combine the two (if you want) to add a green check mark and a red cross to the colored text to give additional visual cues to your users. Hope this helps get you started... Best regards, Cord >-------- Set a color lines in ListBox http://www.greatis.com/delphicb/tips/lib/components-colorline.html First of all, you should set Style method to lbOwnerDrawFixed. And then use OnDrawItem event with lines: procedure TForm1.ListBox1DrawItem( Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); var Mas: array[1..5] of Integer; begin Mas[1]:=clRed; Mas[2]:=clBlue; Mas[3]:=clYellow; Mas[4]:=clAqua; Mas[5]:=clGreen; with (Control as TListBox).Canvas do begin Brush.Color:=Mas[Index+1]; FillRect(Rect); TextOut(Rect.Left,Rect.Top,IntToStr(Index+1)); end; end; - --------< >-------- Stick graphics in ListBox http://www.greatis.com/delphicb/tips/lib/components-stickgraphic.html Use OnDrawItem event for inserting graphics into Listbox or Combobox. Change ItemHeight property for changing size of picture. Don't forget change Style property to lbOwnerDrawFixed. procedure TForm1.ListBox1DrawItem( Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); var Bitmap: TBitmap; R: TRect; Mas: array[1..3] of string; i: Integer; begin Mas[1]:='Pict1.bmp'; Mas[2]:='Pict2.bmp'; Mas[3]:='Pict3.bmp'; with (Control as TListBox).Canvas do begin Bitmap:=TBitmap.Create; FillRect(Rect); Bitmap.LoadFromFile('C:\Pictures\'+Mas[Index+1]); if Bitmap<>nil then begin R:=Bounds( Rect.Left+2, Rect.Top+2, Rect.Bottom-Rect.Top-2, Rect.Bottom-Rect.top-2); StretchDraw(R,Bitmap); end; TextOut(Rect.Left+100,Rect.Top,Mas[Index+1]); Bitmap.Free; end; end; - --------< -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (MingW32) iD8DBQFEsgAnTedEB+SVY50RAjdMAJ0YVSEUHpmOMdioFgB9hsdFg6T0eACfXJDP N1gJgDuwJCTwJMFrV+rCkS0= =UGlu -----END PGP SIGNATURE----- _______________________________________________ Delphi mailing list -> Delphi@elists.org http://www.elists.org/mailman/listinfo/delphi