Background image from embedded resource

P

Peter Zentner

Hi,

I have a bitmap as an embedded resource. Now I want to use that bitmap for a
background image of a button. But if I do the following it doesn't work.

<snap start>
Dim s As System.IO.Stream =
Me.GetType().Assembly.GetManifestResourceStream("WindowsApplication1.Bitmap1
..bmp")
Dim bmp as bitmap = New Bitmap(s)
s.Close()
Dim img As Image = bmp
Button1.BackgroundImage = bmp
<snap end>

What am I doing wrong?

TIA

Peter
 
A

Andrey Zvyagilskiy[MSFT]

that what wizard does:
this.button1.BackgroundImage =
((System.Drawing.Image)(resources.GetObject("button1.BackgroundImage")));

try to do something like this
 
P

Peter Zentner

I found the error: I must not close the stream and I have to do the
following:

Dim s as System.IO.Stream =
Me.GetType().Assembly.GetManifestResourceStream("WindowsApplication1.Bitmap1
..bmp")
Button1.BackgroundImage = new Bitmap(s)

That's all.

:)

Peter
 

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

Similar Threads


Top