Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Icon transparency fails in ListViews etc.
 

Icon transparency fails in ListViews etc.

Hi,I have a question aboutIcons display in windows forms. Trying to get it right in a collegues application, since i'm responsible for graphics...

We are using the same PNG 24 bit icon with transparency in a listview as well as directly on an ordinary form. They display differently.

Example:



http://www.wilfing.se/forum/bells.png

In the listview it looks like the left one, adding some kind of blue stroke where it should be partlytransparent, whilst the othere one added right on a form renders correctly without any blue stroke...

This only fails in Windows XP!! Please help me out! I would be very greatful..

(VB .NET 3.5, VS 2008) Thanks/Jesper

AdmiralGanja  Friday, November 28, 2008 7:37 AM

Hi AdmiralGanja,

I don’t know how you set the icon of the ListView items. I think this problem might be caused by the ColorDepth. Here is my code to set the icon of the three items in my test ListView.

Code Snippet

partial class Form1 : Form

{

private ImageList imgList = new ImageList();

public Form1()

{

InitializeComponent();

Image img = Image.FromFile(@"D:\icon.bmp");

imgList.Images.Add(img);

imgList.ImageSize = new Size(100, 100);

imgList.ColorDepth = ColorDepth.Depth32Bit;

listView1.LargeImageList = imgList;

listView1.Items[0].ImageIndex = 0;

listView1.Items[1].ImageIndex = 0;

listView1.Items[2].ImageIndex = 0;

}

When I set the ColorDepth property of the ImageList to Depth32Bit, it looks greate event the size is very big (100X100). But system will use Depth8Bit as default value if you don’t set it. Then the icon looks really ugly when it is larger.

Please try that and tell me if it works.

Sincerely,

Kira Qian

Kira Qian  Monday, December 01, 2008 7:42 AM

Hi AdmiralGanja,

I don’t know how you set the icon of the ListView items. I think this problem might be caused by the ColorDepth. Here is my code to set the icon of the three items in my test ListView.

Code Snippet

partial class Form1 : Form

{

private ImageList imgList = new ImageList();

public Form1()

{

InitializeComponent();

Image img = Image.FromFile(@"D:\icon.bmp");

imgList.Images.Add(img);

imgList.ImageSize = new Size(100, 100);

imgList.ColorDepth = ColorDepth.Depth32Bit;

listView1.LargeImageList = imgList;

listView1.Items[0].ImageIndex = 0;

listView1.Items[1].ImageIndex = 0;

listView1.Items[2].ImageIndex = 0;

}

When I set the ColorDepth property of the ImageList to Depth32Bit, it looks greate event the size is very big (100X100). But system will use Depth8Bit as default value if you don’t set it. Then the icon looks really ugly when it is larger.

Please try that and tell me if it works.

Sincerely,

Kira Qian

Kira Qian  Monday, December 01, 2008 7:42 AM
thanks for your answer! I noticed i forgot to answer the answer!! It seems to be working now!
/Jesper


/Jesper
AdmiralGanja  Friday, August 14, 2009 6:11 AM

You can use google to search for other answers

Custom Search

More Threads

• Visual inheritance in derived Forms
• Question about Custom Control on Focus, Cursor
• Need to do a context Menu on the design surface
• UITypeEditor and Modal form not showing
• 2 WinForm bugs
• How to display values in a Groupbox
• Problem when adding a custom control to a form
• Howto include designtime help for a component
• When/Where should I instantiate the control when placing on the designer
• Unable to select individual control on a Custom control