[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

500pts: Assigning an icon to a form from Imagelist looses transparency.

Posted on 2006-11-28
7
Medium Priority
?
182 Views
Last Modified: 2010-04-16
Hi there,

Can anyone help, i am using the following code to convert a bitmap with transparency that is stored in a ImageList to an icon for use on my form...

Here is the code, but for some reason where the icons looks really nice in windows explorer, imagelist etc... when i pull it into my form it shows a thick blue colour where the transparency was supposed to be...

                  this.Icon = Icon.FromHandle(((Bitmap)ImageList1.Images[0]).GetHicon());

Does anyone know a work around for this

Thanks in advance

Ian
0
Comment
Question by:ianinspain
  • 3
  • 3
7 Comments
 
LVL 29

Expert Comment

by:Nightman
ID: 18026600
As far as I know, you have to set the transaprency key on the form. The simple approach is to go to form properties in the IDE, scroll down to windows style and then change TransparencyKey to the color that you want.
0
 
LVL 29

Expert Comment

by:Nightman
ID: 18026611
Or from code (if you don't like the pallette and want to explicitly set an RGB value)

this.TransparencyKey = System.Drawing.Color.FromArgb((int)((byte)(0)), (int)((byte)(0)), (int)((byte)(64)));
0
 

Author Comment

by:ianinspain
ID: 18026858
Thanks for that... but the problem is.. that it is png file .. so the transparency is actually transparency....

I understand that i have to set the transparency colour of the form... thanks.....

But how would i know which colour to set it too.... its obviously changing the transparency in the png to something?

Ian
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 29

Assisted Solution

by:Nightman
Nightman earned 800 total points
ID: 18026905
Do you need to do this programatically at run time, or can this be preset on the form?

Try opening the image in MS Paint
Use the eye dropper tool to suck up the colour, then go to Colors -> Edit Colors
In there if you press Define custom Colors you can see the RGB values. Then take those RGB values and use them in the form
0
 

Author Comment

by:ianinspain
ID: 18027086
Thanks ... that seem to work but  i got black... but changing the Transpareny key of the form.. doesn't seem to effect the icon but effects everything that is on the form i.e. buttons, text etc...alot of stuff disappears due to the fact ...i suppose of the key..

Ian
0
 
LVL 1

Accepted Solution

by:
R_Spruit earned 1200 total points
ID: 18038374
The transparency key of the form has nothing to to with this problem, that is only needed if you want to make the form itself transparant. I'm just guessing here, but is the colordepth of your imagelist set correctly? (to 24 bit or something). Maybe the image in the list is returned in the colordepth of the imagelist. If that colordepth is too low the transparancy will be removed.

Roel
0
 

Author Comment

by:ianinspain
ID: 18075769
Hi R_Spruit... yep you were close there... it was true that in the imagelist... the bits were set wrong... so in the imagelist it looks bettter now but still imports back to icon with the problem..

I am going to split points for the help, i have decided to use a .ico instead of a png... which fixed the problem..

Ian
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question