Solved

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

Posted on 2006-11-28
7
171 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 29

Assisted Solution

by:Nightman
Nightman earned 200 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

763 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

6 Experts available now in Live!

Get 1:1 Help Now