Solved

C++ Builder - need colored text in TListBox et al

Posted on 2002-06-26
8
568 Views
Last Modified: 2013-12-03
without using a 3rd party component, is there a simple way to color the text in TListBox, TComboBox, TStringGrid ans TTreeView?

If not color, maybe I could just use bold/italic, etc.  Ideally I would like 4 colours, but could live with being able to distinguish 2.

The simpler the solution, the better.
0
Comment
Question by:A_student
  • 4
  • 2
  • 2
8 Comments
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
0
 

Author Comment

by:A_student
Comment Utility
Thanks, but if I need to use 3 party components, I will use something from http://www.tmssoftware.com

However, I would strongly prefer to do it wthout 3rd party compnents if possible.
0
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
but i think, the site is also from borland...
0
 

Author Comment

by:A_student
Comment Utility
sure, it's from borland, but it is listing 3rd party components, nor Borland components.

As far as I know, it is not possible to do what I am asking with the standard compenents.

I am 99% sure, but just want to see if anyone knows better. If it can't be done, then I will use the TMS components, which are free and can do what I want to do.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:A_student
Comment Utility
sure, it's from borland, but it is listing 3rd party components, nor Borland components.

As far as I know, it is not possible to do what I am asking with the standard compenents.

I am 99% sure, but just want to see if anyone knows better. If it can't be done, then I will use the TMS components, which are free and can do what I want to do.
0
 
LVL 6

Accepted Solution

by:
graham_k earned 138 total points
Comment Utility
Create an event handler for the listbox's OnDrawItem event, and put code like this in it:

    TCanvas *pCanvas = ((TListBox *)Control)->Canvas;
    if (((TListBox *)Control)->Items->Strings[Index]=="Red")
        pCanvas->Font->Color=clRed;
    else if (((TListBox *)Control)->ItemIndex==Index) {
        pCanvas->Font->Color=clHighlightText;
    else
        pCanvas->Font->Color=clWindowText;

    pCanvas->FillRect(Rect);
    pCanvas->TextOut(Rect.Left,Rect.Top,
         ((TListBox *)Control)->Items->Strings[Index]);


This code will display the listbox normally, except that any item with the text "Red" will be colored red.  You can adjust the if statements to suit your needs, of course, but you should leave the last two if you have any items you don't want special behavior for.
0
 
LVL 6

Expert Comment

by:graham_k
Comment Utility
0
 

Author Comment

by:A_student
Comment Utility
That worked a treat. Thanks.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now