ListBox项目可以跨多行吗? C#

时间:2013-08-21 14:58:24

标签: c# .net winforms

我想让ListBox控件包含跨越多行的项目。

基本上我想要的是每个项目跨越多行并可作为一个项目选择。有没有办法做到这一点?

1 个答案:

答案 0 :(得分:6)

正如LarsTech在其评论中所建议的那样,所有其他评论都会导致某种完全编码的例子,这可能会使您感到困惑。我用几行代码制作了这个演示程序,供您遵循并轻松开始:

 listBox1.DrawMode = DrawMode.OwnerDrawVariable;
 //First add some items to your listBox1.Items     
 //MeasureItem event handler for your ListBox
 private void listBox1_MeasureItem(object sender, MeasureItemEventArgs e)
 {
   if (e.Index == 2) e.ItemHeight = 50;//Set the Height of the item at index 2 to 50
 }
 //DrawItem event handler for your ListBox
 private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
 {
   e.DrawBackground();
   e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds);
 }

enter image description here