How can I make some items in a ListBox bold?

前端 未结 5 1963
隐瞒了意图╮
隐瞒了意图╮ 2020-12-31 03:28

In Visual c# Express Edition, is it possible to make some (but not all) items in a ListBox bold? I can\'t find any sort of option for this in the API.

5条回答
  •  攒了一身酷
    2020-12-31 04:13

    To add to Mindaugas Mozūras's solution, I had a problem where my e.Bounds wasn't large enough and text was getting cut off. To solve this problem (thanks to a post here), you override the OnMeasureItem event and changes your DrawMode to DrawMode.OwnerDrawVariable.

    In designer:

    listBox.DrawMode = DrawMode.OwnerDrawVariable;
    

    In handler:

    void listBox_MeasureItem(object sender, MeasureItemEventArgs e)
    {
         e.ItemHeight = 18;
    }
    

    Solved my issues of having the height cut off text.

提交回复
热议问题