Click here to Skip to main content
Click here to Skip to main content

Using embedded resources with .NET

By , 30 Mar 2003
Rate this:
Please Sign up or sign in to vote.

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)

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Sander Schreurs
Web Developer
Netherlands Netherlands
I started with VB4 in 1996, after that VB5 and VB6. Always advanced database applications (Oracle, Access and SQL-Server). The last 5 years as a technical architect and project manager for development teams.
 
Special interest for user interaction.

Comments and Discussions

 
GeneralMy vote of 5 Pinmemberdrummerboy051125-Mar-11 11:32 
Generalhello^^ PinmemberDemantorr17-Jan-10 13:06 
GeneralWrong title Pinmember-R-y-a-n-28-Oct-07 1:25 
GeneralAlways getting error when added new icon Pinmemberyj80018-Aug-07 22:39 
GeneralThis worked for me :) Pinmember3DWebGuy9-Jun-05 10:32 
GeneralSame problem with cursors Pinmembermfortin4-Sep-03 22:52 
Generalshowhelp embedded resource chm file Pinmembermdg1710-Jul-03 8:08 
GeneralMinor Improvement PinmemberSander Schreurs31-Mar-03 4:55 
GeneralTell More PinmemberPoolbeer30-Mar-03 19:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140421.2 | Last Updated 31 Mar 2003
Article Copyright 2003 by Sander Schreurs
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid