Solved

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

Posted on 2002-06-26
8
590 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
[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
  • 4
  • 2
  • 2
8 Comments
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 7109984
0
 

Author Comment

by:A_student
ID: 7109998
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
ID: 7110003
but i think, the site is also from borland...
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:A_student
ID: 7110141
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
 

Author Comment

by:A_student
ID: 7110166
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
ID: 7110172
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
 

Author Comment

by:A_student
ID: 7116135
That worked a treat. Thanks.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

724 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