Clyde Eisenbeis

Clyde Eisenbeis

  • 1.6k
  • 54
  • 6.5k

How do I programmically change the Foreground color in a ListBox

Mar 19 2024 10:57 PM

I know that this code

public void FillListBoxColoredText(ListBox LBx, List<string> liststX)
{
  int iCount = liststX.Count();
  for (int ii = 0; ii < iCount; ii++) {
    if (liststX[ii].Contains("blue"))
        LBx.Items.Add(liststX[ii], Foreground = #0000ff);
    else if (liststX[ii].Contains("red"))
        LBx.Items.Add(liststX[ii], Foreground = #ff0000);
    else if (liststX[ii].Contains("green"))
        LBx.Items.Add(liststX[ii], Foreground = #00ff00);
}

is not correct.    It strives to indicate what I want.


Answers (2)