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

CPS*_*CPS 2 .net c# winforms

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

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

Kin*_*ing 7

正如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);
 }
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述