We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Colour or formatting in a Delphi List Box (TListBox)

sheepfarmer
sheepfarmer asked
on
Medium Priority
2,935 Views
Last Modified: 2013-11-23
Is it possible to apply some basic formatting (bold, colour) to one entry in a list box rather than apply formatting to all items in the list box.

If not, what would be a good component to achive:
BOLD TEXT [heading]
GREEN TEXT [sub heading]
NORMAL TEXT [regular data]

Thanks
SF
Comment
Watch Question

There is the demo in Demos folder called Ownerlist which shows exactly you want to do.
(ListBox1 has OwnerDraw property set to true)
procedure TForm1.DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  with ListBox1.Canvas do
  begin
    FillRect(Rect);
    Font.Name := ListBox1.Items[Index];
    Font.Size := 0;    // use font's preferred size
    TextOut(Rect.Left+1, Rect.Top+1, ListBox1.Items[Index]);
  end;
end;
 
procedure TForm1.ListBox1MeasureItem(Control: TWinControl; Index: Integer;
  var Height: Integer);
begin
  with ListBox1.Canvas do
  begin
    Font.Name := Listbox1.Items[Index];
    Font.Size := 0;                 // use font's preferred size
    Height := TextHeight('Wg') + 2; // measure ascenders and descenders
  end;
end;

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Thanks - will check it out and report back.

Author

Commented:
Not tried yet, but it looks reasonabe.  Thanks for your help
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.