Winform customize listbox item

给你一囗甜甜゛ 提交于 2019-12-13 15:44:30

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/2128608/winform-customize-listbox-item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!