Toolbar: Bitmaps with transparent Background?

B

Boris Nienke

Hi,

how to draw small toolbar-icons (16x16 pixels) with transparency?
Currently all my icons have a white background which doesn't look
good...

Boris
 
B

Benjamin Wulfe

You may be experiencing a problem with the way ImageList objects are stored
to the applications .resources. Currently, icons added to an ImageList
lose thier transparency key if they are added to an imagelist on a form.
To get around this, you should add the icon at the project level and
manually load it to your toolbar button after InitializeComponent has been
called.

-Ben

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: Boris Nienke <[email protected]>
| Subject: Toolbar: Bitmaps with transparent Background?
| MIME-Version: 1.0
| Content-Type: text/plain; charset="us-ascii"
| Content-Transfer-Encoding: 7bit
| Date: Thu, 31 Jul 2003 18:50:46 +0200
| Message-ID: <[email protected]>
| User-Agent: 40tude_Dialog/2.0.5.1
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| NNTP-Posting-Host: p50864dfd.dip0.t-ipconnect.de 80.134.77.253
| Lines: 1
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:29865
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| Hi,
|
| how to draw small toolbar-icons (16x16 pixels) with transparency?
| Currently all my icons have a white background which doesn't look
| good...
|
| Boris
|
 
B

Boris Nienke

:'( too sad... but good to know that it isn't me who did something wrong ;)

BTW: do have an example on how to load the bitmaps manually to the
toolbar-buttons?

thank you

Boris
 
B

Benjamin Wulfe

Try this out:

1. Create a project called "WindowsApplication1"
2. Add an icon called "MSN.ICO" to the project
3. In the properties for the icon (click on it in the solution explorer),
select "Embedded Resource" for "Build Action"
4. Open Form1
5. Add a toolbar, and then a toolbarbutton in the toolbar
6. Add an imagelist component
7. Add the following in the constructor for the Form _AFTER_ the call to
InitializeComponent.

Icon icon = new
Icon(this.GetType().Module.Assembly.GetManifestResourceStream("WindowsApplic
ation1.MSN.ICO"));
this.imageList1.Images.Add(icon);
this.toolBar1.ImageList = this.imageList1;
this.toolBarButton1.ImageIndex = 0;

you should then see the icon with transparency correctly applied to the
button on your toolbar.

-Ben

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: Boris Nienke <[email protected]>
| Subject: Re: Toolbar: Bitmaps with transparent Background?
| MIME-Version: 1.0
| Content-Type: text/plain; charset="us-ascii"
| Content-Transfer-Encoding: 7bit
| References: <[email protected]>
<[email protected]>
| Date: Wed, 20 Aug 2003 10:43:05 +0200
| Message-ID: <[email protected]>
| User-Agent: 40tude_Dialog/2.0.5.1
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| NNTP-Posting-Host: 217.5.221.2
| Lines: 1
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:31416
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| :'( too sad... but good to know that it isn't me who did something wrong
;)
|
| BTW: do have an example on how to load the bitmaps manually to the
| toolbar-buttons?
|
| thank you
|
| Boris
|
| On Mon, 18 Aug 2003 22:48:57 GMT, Benjamin Wulfe wrote:
|
| > You may be experiencing a problem with the way ImageList objects are
stored
| > to the applications .resources. Currently, icons added to an ImageList
| > lose thier transparency key if they are added to an imagelist on a
form.
| > To get around this, you should add the icon at the project level and
| > manually load it to your toolbar button after InitializeComponent has
been
| > called.
| >
| > -Ben
| >
| > This posting is provided "AS IS" with no warranties, and confers no
rights.
| > --------------------
| >|
| >| Hi,
| >|
| >| how to draw small toolbar-icons (16x16 pixels) with transparency?
| >| Currently all my icons have a white background which doesn't look
| >| good...
| >|
| >| Boris
| >|
|
 
S

Stumpy842

The code below may work for transparent icons (I don't know I didn't use
it with icons) but the problem I'm having is with 32bppArgb .PNG files.
I added a version of this code to my project changing icon to image and
the images are added to the imagelist ok but still lose their
transparency! I'd read that they will lose it if added in the VS
Designer but should work if added programatically as I'm doing. But alas
that doesn't work... anyone have any ideas?

I really wanted to add them to an imagelist to facilitate switching
images on buttons etc. I'm want to use names from an enum to specify the
images but this gets messy if I have to create an array of images, it's
just not as elegant!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top