<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Farbige einträge in ListBox]]></title><description><![CDATA[<p>Hallo !</p>
<p>Ich würde gerne in meiner Listbox &quot;TitleList&quot; zur besseren übersicht jeden 2ten eintrag fablich unterlegt haben. Mit dem Code unten klappt das soweit auch aber sobald man die Listbox schnell hoch/runter scrollt oder aber reinklickt und per Pfeiltasten die Einnträge durchläuft verändern sich die Farben. Was kann ich machen ? Danke !</p>
<p>col1 &amp; col2 sind Boolsche Werte beide mit true init.</p>
<pre><code>void __fastcall TForm1::TitleListDrawItem(TWinControl *Control, int Index,
      TRect &amp;Rect, TOwnerDrawState State)
{

  if ( col1 &amp;&amp; col2 )
  {
  TitleList-&gt;Canvas-&gt;Brush-&gt;Color=clSkyBlue;
  TitleList -&gt; Canvas -&gt; FillRect(Rect);
  }
  col2=!col2;

 TitleList -&gt; Canvas -&gt; Font -&gt; Color = clBlack;

  TitleList -&gt; Canvas -&gt; TextOut(0, Rect.Top,TitleList -&gt; Items -&gt; Strings[Index]);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/100069/farbige-einträge-in-listbox</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Jul 2026 05:35:54 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/100069.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 03 Feb 2005 13:12:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Farbige einträge in ListBox on Thu, 03 Feb 2005 13:12:03 GMT]]></title><description><![CDATA[<p>Hallo !</p>
<p>Ich würde gerne in meiner Listbox &quot;TitleList&quot; zur besseren übersicht jeden 2ten eintrag fablich unterlegt haben. Mit dem Code unten klappt das soweit auch aber sobald man die Listbox schnell hoch/runter scrollt oder aber reinklickt und per Pfeiltasten die Einnträge durchläuft verändern sich die Farben. Was kann ich machen ? Danke !</p>
<p>col1 &amp; col2 sind Boolsche Werte beide mit true init.</p>
<pre><code>void __fastcall TForm1::TitleListDrawItem(TWinControl *Control, int Index,
      TRect &amp;Rect, TOwnerDrawState State)
{

  if ( col1 &amp;&amp; col2 )
  {
  TitleList-&gt;Canvas-&gt;Brush-&gt;Color=clSkyBlue;
  TitleList -&gt; Canvas -&gt; FillRect(Rect);
  }
  col2=!col2;

 TitleList -&gt; Canvas -&gt; Font -&gt; Color = clBlack;

  TitleList -&gt; Canvas -&gt; TextOut(0, Rect.Top,TitleList -&gt; Items -&gt; Strings[Index]);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/713673</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/713673</guid><dc:creator><![CDATA[Karlo234]]></dc:creator><pubDate>Thu, 03 Feb 2005 13:12:03 GMT</pubDate></item><item><title><![CDATA[Reply to Farbige einträge in ListBox on Thu, 03 Feb 2005 13:14:44 GMT]]></title><description><![CDATA[<p>Was genau bezweckst du mit der if-Abfrage? Warum nicht einfach modulo 2 (Index % 2) auf Null prüfen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/713677</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/713677</guid><dc:creator><![CDATA[Dasd]]></dc:creator><pubDate>Thu, 03 Feb 2005 13:14:44 GMT</pubDate></item><item><title><![CDATA[Reply to Farbige einträge in ListBox on Thu, 03 Feb 2005 13:49:11 GMT]]></title><description><![CDATA[<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /> Ok richtig ist wohl nicht allzu schick aber das ist nicht das eigendliche Problem oder ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/713709</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/713709</guid><dc:creator><![CDATA[Karlo234]]></dc:creator><pubDate>Thu, 03 Feb 2005 13:49:11 GMT</pubDate></item><item><title><![CDATA[Reply to Farbige einträge in ListBox on Thu, 03 Feb 2005 13:58:19 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">void __fastcall TfMain::lbCheatListDrawItem(TWinControl *Control,
      int Index, TRect &amp;Rect, TOwnerDrawState State)
{
    lbCheatList-&gt;Canvas-&gt;Font-&gt;Assign(fMain-&gt;Font);
    lbCheatList-&gt;Canvas-&gt;Font-&gt;Size=8;
    lbCheatList-&gt;Canvas-&gt;Font-&gt;Color=0xa000+(Index&amp;1)*0x5000;
    lbCheatList-&gt;Canvas-&gt;Brush-&gt;Color=(Index&amp;1)*0x5000;
    lbCheatList-&gt;Canvas-&gt;Pen-&gt;Style=psSolid;
    if(State.Contains(odSelected))
    {
        lbCheatList-&gt;Canvas-&gt;Font-&gt;Color=(Index&amp;1)*0x5000;
        lbCheatList-&gt;Canvas-&gt;Brush-&gt;Color=0xa000+(Index&amp;1)*0x2800;
    }
    lbCheatList-&gt;Canvas-&gt;Pen-&gt;Color=lbCheatList-&gt;Canvas-&gt;Brush-&gt;Color;
    lbCheatList-&gt;Canvas-&gt;Rectangle(Rect);
    lbCheatList-&gt;Canvas-&gt;Brush-&gt;Style=bsClear;
    lbCheatList-&gt;Canvas-&gt;TextOut(Rect.Left+4,
        Rect.Top+Rect.Height()*0.5-lbCheatList-&gt;Canvas-&gt;TextHeight(&quot;T&quot;)*0.5,
        IntToStr(Index+1));
    lbCheatList-&gt;Canvas-&gt;Pen-&gt;Color=lbCheatList-&gt;Canvas-&gt;Font-&gt;Color;
    lbCheatList-&gt;Canvas-&gt;MoveTo(Rect.Left+47,Rect.Top);
    lbCheatList-&gt;Canvas-&gt;LineTo(Rect.Left+47,Rect.Bottom);
    lbCheatList-&gt;Canvas-&gt;TextOut(Rect.Left+50,
        Rect.Top+Rect.Height()*0.5-lbCheatList-&gt;Canvas-&gt;TextHeight(&quot;T&quot;)*0.5,
            lbCheatList-&gt;Items-&gt;Strings[Index]);
}
</code></pre>
<p>Zum Verständnis:<br />
<a href="http://www.cpp-club.net/page/index.php?frame=downloads/index.php" rel="nofollow">Übersicht</a><br />
<a href="http://www.cpp-club.net/page/index.php?frame=downloads/source.php&amp;project=Cheater+v4.1&amp;dir=cht&amp;f=main.cpp&amp;plang=cpp" rel="nofollow">Source</a></p>
<p>Und so sieht's dann aus:<br />
<a href="http://www.cpp-club.net/page/index.php?frame=downloads/gallery.php&amp;dir=cht&amp;project=Cheater+v4.1" rel="nofollow">Mittleres Bild</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/713712</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/713712</guid><dc:creator><![CDATA[Windoof]]></dc:creator><pubDate>Thu, 03 Feb 2005 13:58:19 GMT</pubDate></item><item><title><![CDATA[Reply to Farbige einträge in ListBox on Fri, 04 Feb 2005 09:01:31 GMT]]></title><description><![CDATA[<p>Karlo234 schrieb:</p>
<blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /> Ok richtig ist wohl nicht allzu schick aber das ist nicht das eigendliche Problem oder ?</p>
</blockquote>
<p>Ich denke schon. Da du col2 immer wieder negierst, machst du die Ausgabe vom vorherigen Zustand abhängig. Allerdings kannst du nicht wisssen, wie der war und somit verunstaltet es deine Anzeige. Deswegen über den mitgelieferten Index gehen, da der immer konstant (für denselben Eintrag) bleibt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/714294</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/714294</guid><dc:creator><![CDATA[Dasd]]></dc:creator><pubDate>Fri, 04 Feb 2005 09:01:31 GMT</pubDate></item></channel></rss>