<?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[FAQ-Verbesserung]]></title><description><![CDATA[<p>Betrifft: FAQ-Eintrag (<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39191.html" rel="nofollow">ListBox - farbige Einträge</a>)</p>
<p>Der Code dort ist nicht schön. Vor allem an einer Stelle undefiniert, denn LBColors[3-Index] existiert nicht für Index == 0. Der Code</p>
<pre><code class="language-cpp">// Hintergrund zeichnen 
  ListBox1-&gt;Canvas-&gt;FillRect(Rect);
</code></pre>
<p>ist zudem überflüssig, da das Rechteck eh mit der in ListBox1-&gt;Canvas-&gt;Brush-&gt;Color angegebenen Farbe gefüllt wird. Mein Verbessrungsvorschlag wäre</p>
<pre><code class="language-cpp">TColor LBTextColors[3] = {clWhite, clLime, clBlack};
TColor LBBrushColors[3] = {clBlue, clBlack, clWhite};

void __fastcall TForm1::ListBox1DrawItem(TWinControl *Control, int Index,
      TRect &amp;Rect, TOwnerDrawState State)
{
  if(State.Contains(odSelected))
  {
    ListBox1-&gt;Canvas-&gt;Brush-&gt;Color = clYellow;   // Hintergrundfarbe
    ListBox1-&gt;Canvas-&gt;Font-&gt;Color = clRed;  // Textfarbe
  }
  else
  {
    ListBox1-&gt;Canvas-&gt;Brush-&gt;Color = LBBrushColors[Index]; // dito
    ListBox1-&gt;Canvas-&gt;Font-&gt;Color = LBTextColors[Index];
  }

  // Text zeichnen
  ListBox1-&gt;Canvas-&gt;TextRect(Rect, Rect.Left, Rect.Top,
                             ListBox1-&gt;Items-&gt;Strings[Index]);

  if(State.Contains(odFocused))
    ListBox1-&gt;Canvas-&gt;DrawFocusRect(Rect);
}
</code></pre>
<p>Es ist noch zu bemerken, dass das Zeichnen des FocusRects letzteres gerade NICHT erscheinen lässt. Beim Weglassen dieses Codes wird das FocusRect gezeichnet.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/154340/faq-verbesserung</link><generator>RSS for Node</generator><lastBuildDate>Sun, 09 Aug 2026 12:03:47 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/154340.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 26 Jul 2006 12:43:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to FAQ-Verbesserung on Wed, 26 Jul 2006 12:43:10 GMT]]></title><description><![CDATA[<p>Betrifft: FAQ-Eintrag (<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39191.html" rel="nofollow">ListBox - farbige Einträge</a>)</p>
<p>Der Code dort ist nicht schön. Vor allem an einer Stelle undefiniert, denn LBColors[3-Index] existiert nicht für Index == 0. Der Code</p>
<pre><code class="language-cpp">// Hintergrund zeichnen 
  ListBox1-&gt;Canvas-&gt;FillRect(Rect);
</code></pre>
<p>ist zudem überflüssig, da das Rechteck eh mit der in ListBox1-&gt;Canvas-&gt;Brush-&gt;Color angegebenen Farbe gefüllt wird. Mein Verbessrungsvorschlag wäre</p>
<pre><code class="language-cpp">TColor LBTextColors[3] = {clWhite, clLime, clBlack};
TColor LBBrushColors[3] = {clBlue, clBlack, clWhite};

void __fastcall TForm1::ListBox1DrawItem(TWinControl *Control, int Index,
      TRect &amp;Rect, TOwnerDrawState State)
{
  if(State.Contains(odSelected))
  {
    ListBox1-&gt;Canvas-&gt;Brush-&gt;Color = clYellow;   // Hintergrundfarbe
    ListBox1-&gt;Canvas-&gt;Font-&gt;Color = clRed;  // Textfarbe
  }
  else
  {
    ListBox1-&gt;Canvas-&gt;Brush-&gt;Color = LBBrushColors[Index]; // dito
    ListBox1-&gt;Canvas-&gt;Font-&gt;Color = LBTextColors[Index];
  }

  // Text zeichnen
  ListBox1-&gt;Canvas-&gt;TextRect(Rect, Rect.Left, Rect.Top,
                             ListBox1-&gt;Items-&gt;Strings[Index]);

  if(State.Contains(odFocused))
    ListBox1-&gt;Canvas-&gt;DrawFocusRect(Rect);
}
</code></pre>
<p>Es ist noch zu bemerken, dass das Zeichnen des FocusRects letzteres gerade NICHT erscheinen lässt. Beim Weglassen dieses Codes wird das FocusRect gezeichnet.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104573</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104573</guid><dc:creator><![CDATA[WebFritzi]]></dc:creator><pubDate>Wed, 26 Jul 2006 12:43:10 GMT</pubDate></item></channel></rss>