Winform的定制列表框项目 [英] Winform customize listbox item

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

问题描述

我应该显示包含2个字段的数据列表框:时间和信息。而不是显示1行文字,我要显示的每个项目为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.

我怎样才能做到这一点?我可以将对象数组到ListBox绑定,但我怎样称呼呢?谢谢您的回答。

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天全站免登陆