Icon loading for listviews (.ico files)
-
I am encountering the 'black icon' issue when loading .ico files into an ImageList for use with a ListView. If I load the icons into the ImageList as design-time, and pull them out with
' Create icon from ImageList Public Function AssignIcon(ByVal ImgList As ImageList, ByVal indx As Int32) Dim objBitmap As Bitmap Dim objIcon As Icon objBitmap = New Bitmap(ImgList.Images(indx)) objIcon = System.Drawing.Icon.FromHandle(objBitmap.GetHicon) Return objIcon End Function
the icons are visible but any transparency is replaced with black. If I load the the ImageList at runtime, referencing icons which I've declared as embedded resources, with either:Dim ico0 As New Icon(System.Reflection.Assembly.GetExecutingAssembly._ GetManifestResourceStream("APKK.icnCD_16x16.ico")) ImgList.Images.Add(ico0)
orDim ico0 As New Icon(Me.GetType(), "icnCD_16x16.ico") ImgList.Images.Add(ico0)
ALL I get is black boxes. Setting other icons without going through an imagelist (like me.icon) using either of the two above code snippets displays the icon perfectly and preserves the transparency. But again, if I were to pull my icon out of an imagelist to set me.icon, it would not display correctly. So I know it is possible that I can correctly display icons in my application when I do not use an ImageList. Is there any way I can assign an icon to a ListViewItem without using an ImageList? I suspect the answer is yes, but only by overriding the ListView class, and I have no idea where to start with that. Perhaps there is a special technique which I've overlooked for loading the ImageList? I like my icons as they are, and don't really relish the thought of manually turning them into bitmaps... Any help appreciated! Let me know if more info is required. I am using VB.Net 2003. Thank you!