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
Solved

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

Posted on 2002-06-26
8
580 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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