Solved

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

Posted on 2006-11-28
7
177 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

688 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