How to place images in the ListBox items?
-
Hi friends, I am developing windows based application.. I am using ListBox in my application.. I dont know how to insert the images in the listbox control items.. I want to display seperate images for the items in the listbox.. Any help or suggesstion is helpful to do that.. Thanks in advance Regards, SAravanan
-
Hi friends, I am developing windows based application.. I am using ListBox in my application.. I dont know how to insert the images in the listbox control items.. I want to display seperate images for the items in the listbox.. Any help or suggesstion is helpful to do that.. Thanks in advance Regards, SAravanan
First, create a class that contains image, something like this:
public class ListBoxItem { public Image img; public string text; public override ToString() { return text; } }
Then you need to create owner-drawn ListBox (which iherits a ListBox class). First, setDrawMode
property toOwnerDrawFixed
orOwnerDrawVariable
(i like the second one). Then you need to overrideOnMeasureItem
andOnDrawItem
methods. Make sure, you've set right size for the item in measuring method so you can draw it properly later. If you want to use images with alpha channel, useImageList.Draw
which can do the job. -
First, create a class that contains image, something like this:
public class ListBoxItem { public Image img; public string text; public override ToString() { return text; } }
Then you need to create owner-drawn ListBox (which iherits a ListBox class). First, setDrawMode
property toOwnerDrawFixed
orOwnerDrawVariable
(i like the second one). Then you need to overrideOnMeasureItem
andOnDrawItem
methods. Make sure, you've set right size for the item in measuring method so you can draw it properly later. If you want to use images with alpha channel, useImageList.Draw
which can do the job.Will u please post the code.. because i am a newbiew to C#.Net Thanks for ur help Regards, Saravanan