Winform自定义列表框项 [英] Winform customize listbox item

查看:232
本文介绍了Winform自定义列表框项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表框应该显示包含2个字段的数据:时间和消息。而不是显示一行文本,我想要每个项目显示为2行 - 第一行是时间,第二行是消息,其中每一行有不同的风格。

I have a listbox that should display data that contains 2 fields: time and a message. Instead of displaying 1 line of text, I want each item to be displayed as 2 lines - 1st line is the time and the 2nd line is the message, where each line has a different style.

我如何做到这一点?我可以绑定对象数组到列表框,但如何风格呢?感谢您的答复。

How can I do this? I can bind the object array to the listbox, but how do I style it? Thanks for your answers.

推荐答案

我只是在评论中正式发布答案。您需要使用DrawMode属性,在 MSDN库文章。你可以按你喜欢的任何方式绘制文本,包括绘制两行文本。使用大字体或使用DrawMode = OwnerDrawVariable设置ItemHeight属性,以给自己足够的空间用于两行。

I'll just formally post an answer earlier left in a comment. You'll need to use the DrawMode property, there's a good example of a DrawItem event handler in the MSDN Library article. You can draw the text any way you like, including drawing two lines of text. Use a large Font or set the ItemHeight property with DrawMode = OwnerDrawVariable to give yourself enough space for two lines.

这篇关于Winform自定义列表框项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆