Board index » delphi » listbox-style component with colored entries

listbox-style component with colored entries

Hi,

I just thought: "Hey, replace your current listbox with a more
sophisticated one.".

What I do is simple: I add protocoll messages into a listboxm. Simple
lines of text like "success" and "failed"...

And now I wanted to have a different background color for every item.
For example the "failed" ones in red and the "successed" in green.

Which component to use? I thought that this would be a simple demand,
but DSP didn't offer anything.

Any ideas?

 

Re:listbox-style component with colored entries


Put a ListBox on a form and call it ListBox 1 and set it's style to
"lbOwnerDrawFixed" and implement the following event.
Hope this helps,

Alain Sienaert
Cortex
Belgium

procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
  Flags: Longint;

begin
  with ListBox1 do
    begin
      { If the item is not selected, then...}
      if not (odSelected in State) then with Canvas.Brush do
        begin
          { Choose the appropriate color.}
          case Index of
            0: Color:= clBlue;
            1: Color:= clRed;
            2: Color:= clGreen;
          end;
        end;

    { Draw the colored rectangle.}
    ListBox1.Canvas.FillRect(Rect);

    { "Borrowed" this code from TCustomListBox.}
    if Index < Items.Count then
    begin
      Flags := DrawTextBiDiModeFlags(DT_SINGLELINE or DT_VCENTER or
DT_NOPREFIX);
      if not UseRightToLeftAlignment then
        Inc(Rect.Left, 2)
      else
        Dec(Rect.Right, 2);
      DrawText(Canvas.Handle, PChar(Items[Index]), Length(Items[Index]),
Rect,
        Flags);
    end;
  end;
end;

Quote
Holger Lembke <holgers...@hlembke.de> wrote in message

news:pbjfgs892petvv7b3ffgto79asiis50g4v@4ax.com...
Quote
> Hi,

> I just thought: "Hey, replace your current listbox with a more
> sophisticated one.".

> What I do is simple: I add protocoll messages into a listboxm. Simple
> lines of text like "success" and "failed"...

> And now I wanted to have a different background color for every item.
> For example the "failed" ones in red and the "successed" in green.

> Which component to use? I thought that this would be a simple demand,
> but DSP didn't offer anything.

> Any ideas?

Re:listbox-style component with colored entries


Quote
"Alain Sienaert" <sienaert.cor...@skynet.be> wrote:
>Put a ListBox on a form and call it ListBox 1 and set it's style to
>"lbOwnerDrawFixed" and implement the following event.
>Hope this helps,

No it doesn't. Because it does not answer the question, if there is a
existing component, that solves this task.
I can do (and did it already myself, just the way you described it),
but I thought about getting a perhaps more sophisticated methode.
Like, perhaps, a color-array-property, that allows setting an item
color. etc.

Re:listbox-style component with colored entries


In article <3unggs0f1intc5hc559n4nfnaicvk87...@4ax.com>, Holger Lembke
wrote:

Quote
> No it doesn't. Because it does not answer the question, if there is a
> existing component, that solves this task.

Why do you expect others to do the searching for you if you can do it
easily yourself?

Delphi Super Page       http://sunsite.icm.edu.pl/delphi/
  US mirror site:       http://www.cdrom.com/pub/delphi_www/
  German mirror :        
http://ftp.uni-erlangen.de/pub/source/MIRRORS/sunsite.icm.edu.pl/pub/de
lphi
  Other mirrors :       http://ftp.sunet.se/delphi/
Torry's Delphi Pages    http://www.torry.ru/  
the Delphi Box          http://Inner-Smile.com .
                        http://www.delphisource.com/
The DELPHI Deli         http://www.delphix.com/
The Delphi EXchange     http://www.delphiexchange.com/

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Re:listbox-style component with colored entries


"Peter Below (TeamB)" <100113.1...@compuXXserve.com> wrote:

Quote
>Why do you expect others to do the searching for you if you can do it
>easily yourself?

Why don't you read my{*word*128}message?

It stated clearly, that I have done a search before and didn't find
anything.

Re:listbox-style component with colored entries


In article <d5tkgss66ima063qjvtt3o39fdff39m...@4ax.com>, Holger Lembke
wrote:

Quote
> Why don't you read my{*word*128}message?

Oh come on, no need to get physical <G>.

I'm sorry, the sentence about DSP escaped my notice.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Re:listbox-style component with colored entries


"Peter Below (TeamB)" <100113.1...@compuXXserve.com> wrote:

Quote
>I'm sorry, the sentence about DSP escaped my notice.

So I must write down one minus point to your account.

That makes still 23.456 plus points. :-)

Re:listbox-style component with colored entries


Only 23.456? I would guess more like 2345.6
He does do a LOT of problem solving for everyone.

Steve Fields

Quote
Holger Lembke wrote:

> "Peter Below (TeamB)" <100113.1...@compuXXserve.com> wrote:

> >I'm sorry, the sentence about DSP escaped my notice.

> So I must write down one minus point to your account.

> That makes still 23.456 plus points. :-)

Re:listbox-style component with colored entries


Quote
Steve Fields <sfield...@earthlink.net> wrote:
>Only 23.456? I would guess more like 2345.6
>He does do a LOT of problem solving for everyone.

Sorry, minor misunderstanding. We Germans (Peter is, too) separate
numbers with "." in groups of 3. Decimal seperator is the ",".

Just the other way round than you do.

Re:listbox-style component with colored entries


Then I absolutely agree!
Quote
Holger Lembke wrote:

> Steve Fields <sfield...@earthlink.net> wrote:

> >Only 23.456? I would guess more like 2345.6
> >He does do a LOT of problem solving for everyone.

> Sorry, minor misunderstanding. We Germans (Peter is, too) separate
> numbers with "." in groups of 3. Decimal seperator is the ",".

> Just the other way round than you do.

Re:listbox-style component with colored entries


Whhhhaatttt!!!!!!!!
Peter knows German very well ???????????!!!!!!!!!!????????

Cheers

Martin Cremer

"Holger Lembke" <holgers...@hlembke.de> schrieb im Newsbeitrag
news:9dmngsgp3gep558uq23iv903dhqhq30eqq@4ax.com...

Quote
> Steve Fields <sfield...@earthlink.net> wrote:

> >Only 23.456? I would guess more like 2345.6
> >He does do a LOT of problem solving for everyone.

> Sorry, minor misunderstanding. We Germans (Peter is, too) separate
> numbers with "." in groups of 3. Decimal seperator is the ",".

> Just the other way round than you do.

Re:listbox-style component with colored entries


Quote
> Whhhhaatttt!!!!!!!!

> Peter knows German very well ???????????!!!!!!!!!!????????

Prellt deine Tastatur? *g*
;-)

johannes
--
Please reply in this newsgroup only
 - SIP solutions -
http://www.sipsolutions.de/

Re:listbox-style component with colored entries


Nein,

aber wenn es stimmt und Peter Deutscher ist oder war, haut mich das glatt
um. Da kann es schon passieren mit den Fingern auf der Tastatur h?ngen zu
bleiben. Ich wei? nur das er organische Chemie studiert hat; aber das
passiert vielen Leuten.  <g>

Cheers

Martin Cremer

P.S. Sorry for writing this in german. Will never happen again.

"Johannes Berg" <johannes.berg.n...@gmx.net> schrieb im Newsbeitrag
news:390EBAF1.8BBFFCAE@gmx.net...

Quote
> > Whhhhaatttt!!!!!!!!

> > Peter knows German very well ???????????!!!!!!!!!!????????

> Prellt deine Tastatur? *g*
> ;-)

> johannes
> --
> Please reply in this newsgroup only
>  - SIP solutions -
> http://www.sipsolutions.de/

Re:listbox-style component with colored entries


Quote
"Martin Cremer" <Martin.Cre...@tonline.de> wrote:
>Peter Deutscher ist oder war

War? Wollen wir nicht hoffen. Peter, gib ein Lebenszeiten.

(Sorry. Couldn't resist.)

Re:listbox-style component with colored entries


Quote
In article <390ede33@dnews>, Martin Cremer wrote:
> wenn es stimmt und Peter Deutscher ist oder war

Stimmt, und er ist es immer noch <g>.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Other Threads