1

重複の可能性:
ListBox 項目の背景色 (winform)

座標ごとに異なる色が必要な ListBox があります。元。

23,34 //red background
56,78 //green background
90,2 // yellow background

コード:

        for (int i = 0; i < il_kl; i++)
        {
            int il_pkt = Klastry[i].Punkty.Count;
            string color = lista_kolor[i]; 
            Brush mybrush = (Brush)new BrushConverter().ConvertFromString(color);

            for (int j = 0; j < il_pkt; j++)
            {
                x = Klastry[i].Punkty[j].X;
                y = Klastry[i].Punkty[j].Y;

                _mn.kolekcje_wsp.Items.Add(x + " , " + y);
                _mn.kolekcje_wsp.Foreground = mybrush;

            }

        }

今使っていますが、座標ごとに色Foregroundを変えるにはどうすればいいですか?Background

4

1 に答える 1

0

以下を試してみて、それがうまくいくかどうかを確認してください

おそらく、それを達成する唯一の方法は、アイテムを自分で描くことです。

DrawMode を OwnerDrawFixed に設定します。

DrawItem イベントで次のようにコーディングします。

private void listBox_DrawItem(object sender, DrawItemEventArgs e)
{
    e.DrawBackground();
    Graphics myCustomGraphic = e.Graphics;
    myCustomGraphic.FillRectangle(new SolidBrush(Color.Yellow), e.Bounds);
    // Print text
    e.DrawFocusRectangle();
}
于 2012-10-30T21:05:16.513 に答える