Winforms DotNet ListBox items to word wrap if content string width is bigger than ListBox width?

后端 未结 4 1036
死守一世寂寞
死守一世寂寞 2020-12-03 11:37

Ehm, umm, this means some lines should be two-lined in size. My boss think this is more simple solution, than limit displayed text to fit width and don\'t like horizontal sc

4条回答
  •  失恋的感觉
    2020-12-03 11:58

    To make binding correct, be sure to add check "lst.Items.Count > 0" to lst_MeasureItem function. Here is my example:

     if (lst.Items.Count > 0)
     {
        e.ItemHeight = (int)e.Graphics.MeasureString(lst.Items[e.Index].ToString(), lst.Font, lst.Width).Height;
     }
    

    Everything else seems to work nicely after that.

提交回复
热议问题