Solved

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

Posted on 2006-11-28
7
172 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 29

Assisted Solution

by:Nightman
Nightman earned 200 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 300 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

932 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now