Hi .Net folks
I have a ListView with a background image on my Form, which is related to an ImageList to show up pictures that exist in a folder as thumbnails. Everything works fine and ListView shows up thumbnails correctly. But when I try to use TransparentColor property of ImageList to remove unnecessary areas of thumbnails, everything disapears (I mean whole the thumbnail) except texts! Note that, I also used ListViewItem.BackColor = Color.Transparent and ListViewItem.UseItemStyleForSubItems and it did not change anything.
My code is as following and appreciate any help.
Dim ImageList1 As New ImageList()
ImageList1.ImageSize = New Size(160, 120)
ImageList1.ColorDepth = ColorDepth.Depth32Bit
ImageList1.TransparentColor = Color.White
'^This line causes thumbnails to completely disapear, otherwise everything is ok
ListView1.View = View.LargeIcon
ListView1.SmallImageList = ImageList1
ListView1.LargeImageList = ImageList1
ListView1.Sorting = SortOrder.Ascending
Dim di As New DirectoryInfo(Path)
Dim Files() As FileInfo = GetFiles(di, "*.bmp;*.jpg;*.gif", SearchOption.TopDirectoryOnly)
If Files.Count > 0 Then
For Each File As FileInfo In Files
Try
picThumb1.Image = My.Resources.Empty1
'Note: My.Resources.Empty1 is a picture with a white background to make standard size thumbnails from multisize pictures
picThumb2.Image = Image.FromFile(File.FullName, False)
Dim g As Graphics = Graphics.FromImage(picThumb1.Image)
g.InterpolationMode = InterpolationMode.HighQualityBilinear
g.DrawImage(picThumb2.Image, cLeft, cTop, cWidth, cHeight)
'Note: cLeft, cTop, cWidth, cHeight to be calculate elsewhere
g.Dispose()
ImageList1.Images.Add(picThumb1.Image)
ListView1.Items.Add(File.Name, ImageList1.Images.Count - 1)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
Next
End If
I have a ListView with a background image on my Form, which is related to an ImageList to show up pictures that exist in a folder as thumbnails. Everything works fine and ListView shows up thumbnails correctly. But when I try to use TransparentColor property of ImageList to remove unnecessary areas of thumbnails, everything disapears (I mean whole the thumbnail) except texts! Note that, I also used ListViewItem.BackColor = Color.Transparent and ListViewItem.UseItemStyleForSubItems and it did not change anything.
My code is as following and appreciate any help.
Dim ImageList1 As New ImageList()
ImageList1.ImageSize = New Size(160, 120)
ImageList1.ColorDepth = ColorDepth.Depth32Bit
ImageList1.TransparentColor = Color.White
'^This line causes thumbnails to completely disapear, otherwise everything is ok
ListView1.View = View.LargeIcon
ListView1.SmallImageList = ImageList1
ListView1.LargeImageList = ImageList1
ListView1.Sorting = SortOrder.Ascending
Dim di As New DirectoryInfo(Path)
Dim Files() As FileInfo = GetFiles(di, "*.bmp;*.jpg;*.gif", SearchOption.TopDirectoryOnly)
If Files.Count > 0 Then
For Each File As FileInfo In Files
Try
picThumb1.Image = My.Resources.Empty1
'Note: My.Resources.Empty1 is a picture with a white background to make standard size thumbnails from multisize pictures
picThumb2.Image = Image.FromFile(File.FullName, False)
Dim g As Graphics = Graphics.FromImage(picThumb1.Image)
g.InterpolationMode = InterpolationMode.HighQualityBilinear
g.DrawImage(picThumb2.Image, cLeft, cTop, cWidth, cHeight)
'Note: cLeft, cTop, cWidth, cHeight to be calculate elsewhere
g.Dispose()
ImageList1.Images.Add(picThumb1.Image)
ListView1.Items.Add(File.Name, ImageList1.Images.Count - 1)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
Next
End If