Pictures with transparent color to Image-List?

G

Guest

Hello NG!

Is it possible to add a Image (gif) with a transparent color to an
ImageList? I want to have the Image as embedded ressource, but how do I load
it as Image? If I try

Me.ImageList.Images.Add(New
System.Drawing.Bitmap(System.Reflection.Assembly.GetExecutingAssembly().GetM
anifestResourceStream("Assembly.ImageName.gif")))

I get the Image into the ImageList, but not with a transparent color. May
the problem is, that I load it as Bitmap?

Thanks, D.Barisch
 
G

Geoff Schwab [MSFT]

Hi Daniel,

I believe you need to use icons. Here is a related FAQ item from the FAQ
that is to be released tomorrow:

5.42. How do I add Toolbar buttons with transparency?

Icons support transparency, however, there is a known bug in Visual Studio
..NET 2003 designer that creates incorrect code and makes icons
non-transparent. A work around is to add an icon file to the ImageList
outside of InitializeComponent and add the icon files to the project as
content or embedded resources. The following code demonstrates this:
//C#
using System.Drawing;
using System.IO;
using System.Reflection;

// Loaded as content example
private void Form1_Load(object sender, System.EventArgs e)
{
this.imageList1.Images.Add(new Icon(File.Open("fullFileName.ico",
FileMode.Open)));

this.toolBar1.Buttons[0].ImageIndex = 0;
}

// Loaded as a resource example
private void Form1_Load(object sender, System.EventArgs e)
{
this.imageList1.Images.Add(new
Icon(Assembly.GetExecutingAssembly().GetManifestResourceStream(
".filename.ico")));

this.toolBar1.Buttons[0].ImageIndex = 0;
}

'VB
Imports System.Drawing
Imports System.IO
Imports System.Reflection

' Loaded as content example
Private Sub Form1_Load1(ByVal sender As Object, ByVal e As System.EventArgs)

Me.imageList1.Images.Add(New Icon(File.Open("fullFileName.ico", _
FileMode.Open)))

Me.toolBar1.Buttons(0).ImageIndex = 0

End Sub 'Form1_Load1

' Loaded as a resource example
Private Sub Form1_Load2(ByVal sender As Object, ByVal e As System.EventArgs)

Me.imageList1.Images.Add(New _
Icon([Assembly].GetExecutingAssembly().GetManifestResourceStream( _
".filename.ico")))

Me.toolBar1.Buttons(0).ImageIndex = 0

End Sub 'Form1_Load2

--
Geoff Schwab
Program Manager
Excell Data Corporation
http://msdn.com/mobility
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/FAQ/default.aspx

This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Hello Geoff!

Thank your for your reply! But at the moment I'm really troubled about that
problem:

Dim i As New
System.Drawing.Bitmap(System.Reflection.Assembly.GetExecutingAssembly().GetM
anifestResourceStream("AssemblyName.MyImage.bmp"))
Me.ImageList.Images.Add(i)

....works, but on trying

1: Dim i As New
System.Drawing.Icon(System.Reflection.Assembly.GetExecutingAssembly().GetMan
ifestResourceStream("AssemblyName.MyImage.ico"))
2: Me.ImageList.Images.Add(i)

I get a "NotSupportedException" in line "1:" if I try to connect to my
device. If I try to connect with that code to the emulator the connection is
cutted without throwing any exception.

"MyImage.bmp" and "MyImage.ico" are marked as embedded ressources.

What is strange to me is, that I got some code to work and I saw an icon
with transparent color on my device, but after coding it for all the icons I
need, I got this terrifiing error! Even restart Desktop and Device did not
help!

So what's the problem???

Thanks D.Barisch
 
M

Mark Johnson

System.Reflection.Assembly asm =
System.Reflection.Assembly.GetExecutingAssembly();
string[] sa_ResourceNames = asm.GetManifestResourceNames();
sa_ResourceNames = new
string[]{"DataConnection.gif","DataBase_Closed.gif","DataBase_Open.gif",

"Tables.gif","View.gif","Table_Closed.gif","Table_Open.gif",

"Column.gif","Note12.gif","Note12.gif","Note12.gif"};
Bitmap bmp_Work=null;
for (int i=0;i<sa_ResourceNames.Length;i++)
{
// img_Work =
(System.Drawing.Image)asm.GetManifestResourceStream(s_AssemblyName+sa_Resour
ceNames);
bmp_Work = new
Bitmap(asm.GetManifestResourceStream(s_AssemblyName+sa_ResourceNames));
imageListTreeViewDataSet.Images.Add(bmp_Work);
//
imageListTreeViewDataSet.Images.Add(((System.Drawing.Image)(asm.GetManifestR
esourceStream(s_AssemblyName+sa_ResourceNames))));
}
imageListTreeViewDataSet.ImageSize = new System.Drawing.Size(16, 16);

This worked for me, but I had to make sure that the gifs were saved with
transpareny.

Mark Johnson, Berlin Germany
(e-mail address removed)
 

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