Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>By default the text in a ComboBox is drawn in one of two colors:</p> <pre><code>SystemColors.WindowText </code></pre> <p>for non-highlighted items, or</p> <pre><code>SystemColors.HighlightText </code></pre> <p>for highlighted items.</p> <p>These colors are not fixed, but can be configured by the user (e.g., through Control Panel). In a typical Windows color scheme, WindowText is black, and HighlightText is white, but this is not always the case if the color scheme has been reconfigured.</p> <p>To ensure that you get the right colors regardless of how the user has their system configured, and also to get the appropriate color for highlighted vs. non-highlighted text, instead of using Brushes.Black for your non-disabled text, use something like:</p> <pre><code>e.State == DrawItemState.Selected ? SystemBrushes.HighlightText : SystemBrushes.WindowText </code></pre> <p>This basically says, if the state of the item you're drawing (e.State) is Selected (highlighted), use SystemColors.HighlightText, otherwise use SystemColors.WindowText.</p> <p>You may also want to use:</p> <pre><code>SystemBrushes.GrayText </code></pre> <p>instead of Brushes.Gray, again in case the user has a nonstandard color scheme and plain Gray doesn't look right. And, you probably should also use:</p> <pre><code>comboBox1.Font </code></pre> <p>instead of creating an Arial font, to make sure that the font matches the font defined for the ComboBox on the form. (Also creating a Font object and not disposing of it will cause a resource leak.)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload