How can I programatically add an image inside a TListBoxItem?

99封情书 提交于 2019-12-11 10:14:27

问题


Problem

For a long time, I was using a Custom Style to load a detailed TListBox.

It's basically a ListBox with a TImage as an icon.

However recently I've been encountering lots of bugs and decided to throw it all away.

This is how I generate my TListBox items programatically:

   // Create LISTBox Item
   lb_item        := TListBoxItem.Create(self);
   lb_item.Parent := lb_awesome_list;
   lb_item.Text   := cow_name;

What if I would like to add an Image to it?

What I have done so far

I've tried to add it as an ItemData

lb_item.ItemData.Bitmap := iv_user_ic.Bitmap;

And a few other options without success. Is it possible to add an image programatically?


回答1:


The approach with setting the ItemData.Bitmap property is a good start. Now you have to select an appropriate item style to show the bitmap. F.i. listboxitemleftdetail should do.



来源:https://stackoverflow.com/questions/35873478/how-can-i-programatically-add-an-image-inside-a-tlistboxitem

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