Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2002-06-26
8
Medium Priority
?
608 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

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 552 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

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…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

610 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