Image on Windowsform ListBox
-
Can anyone help me understand this. not too much luck finding anything in google? using the following code to display a image in a button works fine button1.Image = global::AppInfo.Properties.Resources.MyImage; But if I trying to display the image on a windows Form listbox, it does not work listBox3.Items.Add(global::AppInfo.Properties.Resources.MyImage); This only displays "System.Drawing.Bitmap" text many thanks in advanced
-
Can anyone help me understand this. not too much luck finding anything in google? using the following code to display a image in a button works fine button1.Image = global::AppInfo.Properties.Resources.MyImage; But if I trying to display the image on a windows Form listbox, it does not work listBox3.Items.Add(global::AppInfo.Properties.Resources.MyImage); This only displays "System.Drawing.Bitmap" text many thanks in advanced
It's because the ListBox control doesn't render images on it's own. You have to custom draw each item in the ListBox yourself. See ListBox.DrawItem Event (System.Windows.Forms) | Microsoft Docs[^]
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
Can anyone help me understand this. not too much luck finding anything in google? using the following code to display a image in a button works fine button1.Image = global::AppInfo.Properties.Resources.MyImage; But if I trying to display the image on a windows Form listbox, it does not work listBox3.Items.Add(global::AppInfo.Properties.Resources.MyImage); This only displays "System.Drawing.Bitmap" text many thanks in advanced
If you add it to a listbox as an item, it will try to find a string-representation of your object. The thing it is displaying means it is working, and correctly. If you want images TO the items, try the
Listbox.ImageList
. There's an example on MSDN.Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
-
Can anyone help me understand this. not too much luck finding anything in google? using the following code to display a image in a button works fine button1.Image = global::AppInfo.Properties.Resources.MyImage; But if I trying to display the image on a windows Form listbox, it does not work listBox3.Items.Add(global::AppInfo.Properties.Resources.MyImage); This only displays "System.Drawing.Bitmap" text many thanks in advanced
You may get more helpful replies here if you describe what the bitmaps you want to display are ... are they icons; do they vary in size, etc. ? Start here: [^] and figure out: 1. would using a ListView or DatagridView be a better choice ... if not ... 2. would the facility to use an 'ImageList with the ListView do what you want ... if not ... 3. are you willing to take on drawing the graphics yourself ... sub-classing the ListView and owner-drawing ... see: [^]
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot