473,408 Members | 1,826 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Accessing embedded resources

Hi all,

I've created a custom button which I can stick into my toolbox. This all
works well and I see my button in the designer. This button uses
customised graphics and I want to stick it in the dll as an embedded
resource. In the project tree I added a folder in which I stick the
bitmaps (png's actually) and set he compile option for them to
EmbeddedResource. But how do I access them from my (vb)source?

The docs say:

new bitmap(type, resourcename)

but what is the resourcename? Where do I find that? I've tried just
entering the filename, but that gives me an error saying it can't be
located in the namespace of my custom button.
--
Rinze van Huizen
C-Services Holland b.v
Feb 8 '06 #1
3 1947

The resource name is <namespace.name>

For example, if you have a bitmap, bar.bmp embedded in a project with a
namespace of foo. Then the resource name is foo.bar.bmp

NOTES: The resource name is case sensitive
It is the namespace that is important not the project name
- by default they are the same but may not be

I have seen the

new bitmap(type, resourcename)

version before and cannot promise that it will work.

I generally use

Dim bmp As New
System.Drawing.Bitmap(System.Reflection.Assembly.G etExecutingAssembly.GetManifestResourceStream
_

(<resourcename>))

hth,
Alan.

Feb 8 '06 #2
Here's a class that I use to retrieve different types of resources (note that
the resource names are case sensitive including any .extension, i.e., .ICO is
different from .ico).

Imports System
Imports System.Reflection
Imports System.Drawing
Imports System.Windows.Forms

Public Class Resources
'WARNING: Icon and Image Names are Case Sensistive
Private Shared Function AssemblyName() As String
Static v_AssemblyName As String
If v_AssemblyName Is Nothing Then v_AssemblyName =
System.Reflection.Assembly.GetExecutingAssembly(). GetName.Name & "."
Return v_AssemblyName
End Function
Public Shared Function GetIcon(ByVal IconName As String) As Icon
Dim asm As [Assembly] = [Assembly].GetExecutingAssembly
Dim v_name As String = IconName
If InStr(v_name.ToLower, ".ico") <= 0 Then v_name = v_name & ".ico"
Dim Name As String = AssemblyName() & v_name
Dim s As System.IO.Stream = asm.GetManifestResourceStream(Name)
If Not s Is Nothing Then
Return New Icon(s)
s.Close()
End If
End Function

Public Shared Function GetImage(ByVal BitMapName As String) As Bitmap
Dim asm As [Assembly] = [Assembly].GetExecutingAssembly
Dim v_name As String = BitMapName
If InStr(v_name.ToLower, ".bmp") <= 0 Then v_name = v_name & ".bmp"
Dim Name As String = AssemblyName() & v_name
Dim s As System.IO.Stream = asm.GetManifestResourceStream(Name)
If Not s Is Nothing Then
Return New Bitmap(s)
s.Close()
End If
End Function

Public Shared Function GetCursor(ByVal CursorName As String) As Cursor
Dim asm As [Assembly] = [Assembly].GetExecutingAssembly
Dim v_name As String = CursorName
If InStr(v_name.ToLower, ".cur") <= 0 Then v_name = v_name & ".cur"
Dim Name As String = AssemblyName() & v_name
Dim s As System.IO.Stream = asm.GetManifestResourceStream(Name)
If Not s Is Nothing Then
Return New Cursor(s)
s.Close()
End If
End Function
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
End Class
--
Dennis in Houston
"C-Services Holland b.v." wrote:
Hi all,

I've created a custom button which I can stick into my toolbox. This all
works well and I see my button in the designer. This button uses
customised graphics and I want to stick it in the dll as an embedded
resource. In the project tree I added a folder in which I stick the
bitmaps (png's actually) and set he compile option for them to
EmbeddedResource. But how do I access them from my (vb)source?

The docs say:

new bitmap(type, resourcename)

but what is the resourcename? Where do I find that? I've tried just
entering the filename, but that gives me an error saying it can't be
located in the namespace of my custom button.
--
Rinze van Huizen
C-Services Holland b.v

Feb 9 '06 #3
al*******@users.com wrote:
The resource name is <namespace.name>

For example, if you have a bitmap, bar.bmp embedded in a project with a
namespace of foo. Then the resource name is foo.bar.bmp

NOTES: The resource name is case sensitive
It is the namespace that is important not the project name
- by default they are the same but may not be

I have seen the

new bitmap(type, resourcename)

version before and cannot promise that it will work.

I generally use

Dim bmp As New
System.Drawing.Bitmap(System.Reflection.Assembly.G etExecutingAssembly.GetManifestResourceStream(<res ourcename>))


Thank you both, that did the trick. I'm keeping Denis' class for future
reference since it was a bit overkill for this particular instance.

--
Rinze van Huizen
C-Services Holland b.v
Feb 10 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Philipp Seidel | last post by:
Hi there! I did not know, where this topic fits in, so I put it here. I have a minor problem with embedded resources, which puzzles me quite a lot. I'd be glad if anyone can help me on this: ...
5
by: Drew | last post by:
Assembly asm = Assembly.GetExecutingAssembly(); me = new Bitmap(asm.GetManifestResourceStream("me.gif")); I have used this before without any problem, but now I get: An unhandled exception...
0
by: Chris Schremser | last post by:
I have a question regarding embedded controls in IE. We are looking to replace a small VB ActiveX control with something written in C#. We have written the control and it instantiates correctly...
2
by: Kyle Kaitan | last post by:
I have an assembly (AppResources.dll) which contains a number of embedded resource files. Most of these are key/value pairs of relevant strings; a few are images and sounds; some more are XML...
7
by: Wysiwyg | last post by:
Is there any way to add an embedded resource to a project without copying it to the project's directory? I have shared resources and don't want each project using the images, xml files, etc. to...
4
by: Jon Rista | last post by:
I have a project where I need to create a windows .exe by compiling code and linking in some resources. This program thats being generated is somewhat unconventional, and I'll explain how. I'm...
0
by: Johann Blake | last post by:
I'm having trouble grasping how ASP.NET correctly locates resources. There is plenty of documentation on this subject but some things are not clear at all. In my ASP.NET application, I have...
0
by: Aleksey Tkachenko | last post by:
Hi All, How to compile the assembly dll to make the embedded resources ( icons ) accessible by ID number? I have one icon compiled with "embedded resource" option, but when I open the dll by VS...
1
by: TastyKarma | last post by:
Was hoping somebody might have some pointers or maybe a link to an article that explains how to add resources inside a DLL project. In a regular project there's the option to "Add ASP .NET Folder"...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.