65.9K
CodeProject is changing. Read more.
Home

Using embedded resources with .NET

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.72/5 (22 votes)

Mar 31, 2003

viewsIcon

116123

downloadIcon

601

Using embedded resources with .NET.

Sample Image - EmbeddedIconDemo.gif

Introduction

Embedded resource in a project is a new thing in .NET. This sample shows how to use it.

Using the code

The form has a button which changes the form icon.

Dim oStream As System.IO.Stream
Dim oAssembly As System.Reflection.Assembly
Dim sIcon As String
Dim oBitmap As Bitmap

If vbON Then
    sIcon = "EmbeddedIconDemo.LIGHTON.ICO"
Else
    sIcon = "EmbeddedIconDemo.LIGHTOFF.ICO"
End If

'open the executing assembly
oAssembly = System.Reflection.Assembly.LoadFrom(Application.ExecutablePath)

'create stream for image (icon) in assembly
oStream = oAssembly.GetManifestResourceStream(sIcon)

'create new bitmap from stream
oBitmap = CType(Image.FromStream(oStream), Bitmap)

'create icon from bitmap
FetchIcon = Icon.FromHandle(oBitmap.GetHicon)