Solved

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

Posted on 2002-06-26
8
583 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
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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
 
LVL 6

Expert Comment

by:graham_k
ID: 7110179
0
 

Author Comment

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

Featured Post

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

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

685 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