Visual Studio .NET 2002.NET 1.0Windows 2000Windows XPIntermediateDevVisual StudioWindows.NETVisual Basic
Using embedded resources with .NET






2.72/5 (22 votes)
Mar 31, 2003

116123

601
Using embedded resources with .NET.
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)