简体   繁体   中英

How can i draw an image in the listbox along with the listboxItem [c# winforms]

(I'm working in winforms using c#) I have a Listbox ,with some items added to it.My problem is i want to draw an image in the left side of each and every items in the listbox.Can anyone suggest any idea? Thanks in advance.

I can do this by using ImageList.

imageList.Draw(ea.Graphics, bounds.Left, bounds.Top,item.ImageIndex);

but i want to use like this

ea.Graphics.DrawImage("someImage",new point);

You should use a listview control not a listbox for this. The listview natively supports imagelist binding and listviewitem has imageindex property so that you can specify the index of the image to render from the imagelist.

Probable approach -

You can have "List item" composed of UI control with image or drawing area (depends on your requirement). This way you should be able to draw.

Check this project from code project

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM