ListBox中的项目可以跨越多行? C# [英] Can ListBox items span multiple lines? C#
本文介绍了ListBox中的项目可以跨越多行? C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想有一个列表框控件包含跨越多行的项目。
I'd like to have a ListBox control contain items that span multiple lines.
基本上我要的是每个项目跨越多行,并进行选择的一个项目。有没有办法做到这一点?
Essentially what I want is each item to span multiple lines and be selectable as one item. Is there a way to do this?
推荐答案
所建议的 LarsTech
在他的意见,其他所有意见导致某种完全codeD的例子,可以迷惑你。我做这个演示用code只是一些线条为你跟踪和轻松上手:
As suggested by LarsTech
in his comment, all the other comments lead to some kind of fully coded example which may confuse you. I made this demo with just some lines of code for you to follow and get started easily:
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);
}
这篇关于ListBox中的项目可以跨越多行? C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文