?
Solved

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

Posted on 2006-11-28
7
Medium Priority
?
179 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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!

 
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

Technology Partners: 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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

741 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