473,769 Members | 7,320 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Load icon from resx

Anybody has a tip of where to find info/example how to retrieve an icon
from a .RESX-file?

/k
Nov 21 '05 #1
15 3648
Dim p As System.Reflecti on.Assembly
p = System.Reflecti on.Assembly.Get ExecutingAssemb ly()
Icons(0) = New System.Drawing. Icon(p.GetManif estResourceStre am(Me.GetType() ,
"GreenBulb.ico" ))
Icons(1) = New System.Drawing. Icon(p.GetManif estResourceStre am(Me.GetType() ,
"YellowBulb.ico "))
Icons(2) = New System.Drawing. Icon(p.GetManif estResourceStre am(Me.GetType() ,
"RedBulb.ic o"))

Hope it helps
Chris

PS. Make sure you make the icons as embedded.

"kurt sune" <ap*@apa.cx> wrote in message
news:uW******** *****@TK2MSFTNG P12.phx.gbl...
Anybody has a tip of where to find info/example how to retrieve an icon
from a .RESX-file?

/k

Nov 21 '05 #2
Dim p As System.Reflecti on.Assembly
p = System.Reflecti on.Assembly.Get ExecutingAssemb ly()
Icons(0) = New System.Drawing. Icon(p.GetManif estResourceStre am(Me.GetType() ,
"GreenBulb.ico" ))
Icons(1) = New System.Drawing. Icon(p.GetManif estResourceStre am(Me.GetType() ,
"YellowBulb.ico "))
Icons(2) = New System.Drawing. Icon(p.GetManif estResourceStre am(Me.GetType() ,
"RedBulb.ic o"))

Hope it helps
Chris

PS. Make sure you make the icons as embedded.

"kurt sune" <ap*@apa.cx> wrote in message
news:uW******** *****@TK2MSFTNG P12.phx.gbl...
Anybody has a tip of where to find info/example how to retrieve an icon
from a .RESX-file?

/k

Nov 21 '05 #3
See the article at:

http://www.codeproject.com/vb/net/embeddedresources.asp
--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com

"kurt sune" <ap*@apa.cx> wrote in message
news:uW******** *****@TK2MSFTNG P12.phx.gbl...
Anybody has a tip of where to find info/example how to retrieve an icon
from a .RESX-file?

/k

Nov 21 '05 #4
See the article at:

http://www.codeproject.com/vb/net/embeddedresources.asp
--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com

"kurt sune" <ap*@apa.cx> wrote in message
news:uW******** *****@TK2MSFTNG P12.phx.gbl...
Anybody has a tip of where to find info/example how to retrieve an icon
from a .RESX-file?

/k

Nov 21 '05 #5
Kurt,
In addition to the other comments.

Rather then storing the icon in a .RESX file, I normally just embed the icon
directly, as its easier to maintain.

Shawn's article shows how to embed the icon directly & retrieve it. Plus
explains why its easier to maintain.
http://www.windojitsu.com/blog/resxsucks.html

My Xml Resource Resolver was written with XML in mind, however it can easily
be used with other resources, such as icons.
http://msmvps.com/jayharlow/archive/.../24/33766.aspx

To use my XmlResourceReso lver "as is" with an icon, use something like:

Public Module TestModule
Dim name As String
Dim resolver As New XmlResourceReso lver(GetType(Te stModule))
Dim absoluteUri As Uri = resolver.Resolv eUri(Nothing, name)
Dim input As Stream = DirectCast(reso lver.GetEntity( absoluteUri,
Nothing, Nothing), Stream)

Dim theIcon As New Icon(input)

End Module

Alternatively you could just extract most of the GetEntity method into its
own class (which gives you a class similar to Shawn's). Something like:

Option Strict On
Option Explicit On

Imports System.IO
Imports System.Globaliz ation
Imports System.Reflecti on

Public Class ResourceLoader

Private ReadOnly m_assembly As [Assembly]
Private ReadOnly m_type As Type

Public Sub New(ByVal type As Type)
m_assembly = type.Assembly
m_type = type
End Sub

Public ReadOnly Property Location() As String
Get
Return m_assembly.Loca tion
End Get
End Property

Public Function GetStream(ByVal name As String) As Stream
Dim culture As CultureInfo = CultureInfo.Cur rentUICulture
Dim stream As Stream

' Try the specific culture
stream = GetManifestReso urceStream(cult ure, name)

' Try the neutral culture
If stream Is Nothing AndAlso Not culture.IsNeutr alCulture Then
stream = GetManifestReso urceStream(cult ure.Parent, name)
End If

' Try the default culture
If stream Is Nothing Then
stream = GetManifestReso urceStream(name )
End If

If stream Is Nothing Then
Throw New FileNotFoundExc eption(Nothing, name)
End If
Return stream

End Function

Private Function GetManifestReso urceStream(ByVa l culture As CultureInfo,
ByVal name As String) As Stream
Try
Dim satellite As [Assembly] =
m_assembly.GetS atelliteAssembl y(culture)
Return satellite.GetMa nifestResourceS tream(m_type, name)
Catch ex As FileNotFoundExc eption
Return Nothing
End Try
End Function

Private Function GetManifestReso urceStream(ByVa l name As String) As
Stream
Return m_assembly.GetM anifestResource Stream(m_type, name)
End Function

End Class

Hope this helps
Jay

"kurt sune" <ap*@apa.cx> wrote in message
news:uW******** *****@TK2MSFTNG P12.phx.gbl...
Anybody has a tip of where to find info/example how to retrieve an icon
from a .RESX-file?

/k

Nov 21 '05 #6
Kurt,
In addition to the other comments.

Rather then storing the icon in a .RESX file, I normally just embed the icon
directly, as its easier to maintain.

Shawn's article shows how to embed the icon directly & retrieve it. Plus
explains why its easier to maintain.
http://www.windojitsu.com/blog/resxsucks.html

My Xml Resource Resolver was written with XML in mind, however it can easily
be used with other resources, such as icons.
http://msmvps.com/jayharlow/archive/.../24/33766.aspx

To use my XmlResourceReso lver "as is" with an icon, use something like:

Public Module TestModule
Dim name As String
Dim resolver As New XmlResourceReso lver(GetType(Te stModule))
Dim absoluteUri As Uri = resolver.Resolv eUri(Nothing, name)
Dim input As Stream = DirectCast(reso lver.GetEntity( absoluteUri,
Nothing, Nothing), Stream)

Dim theIcon As New Icon(input)

End Module

Alternatively you could just extract most of the GetEntity method into its
own class (which gives you a class similar to Shawn's). Something like:

Option Strict On
Option Explicit On

Imports System.IO
Imports System.Globaliz ation
Imports System.Reflecti on

Public Class ResourceLoader

Private ReadOnly m_assembly As [Assembly]
Private ReadOnly m_type As Type

Public Sub New(ByVal type As Type)
m_assembly = type.Assembly
m_type = type
End Sub

Public ReadOnly Property Location() As String
Get
Return m_assembly.Loca tion
End Get
End Property

Public Function GetStream(ByVal name As String) As Stream
Dim culture As CultureInfo = CultureInfo.Cur rentUICulture
Dim stream As Stream

' Try the specific culture
stream = GetManifestReso urceStream(cult ure, name)

' Try the neutral culture
If stream Is Nothing AndAlso Not culture.IsNeutr alCulture Then
stream = GetManifestReso urceStream(cult ure.Parent, name)
End If

' Try the default culture
If stream Is Nothing Then
stream = GetManifestReso urceStream(name )
End If

If stream Is Nothing Then
Throw New FileNotFoundExc eption(Nothing, name)
End If
Return stream

End Function

Private Function GetManifestReso urceStream(ByVa l culture As CultureInfo,
ByVal name As String) As Stream
Try
Dim satellite As [Assembly] =
m_assembly.GetS atelliteAssembl y(culture)
Return satellite.GetMa nifestResourceS tream(m_type, name)
Catch ex As FileNotFoundExc eption
Return Nothing
End Try
End Function

Private Function GetManifestReso urceStream(ByVa l name As String) As
Stream
Return m_assembly.GetM anifestResource Stream(m_type, name)
End Function

End Class

Hope this helps
Jay

"kurt sune" <ap*@apa.cx> wrote in message
news:uW******** *****@TK2MSFTNG P12.phx.gbl...
Anybody has a tip of where to find info/example how to retrieve an icon
from a .RESX-file?

/k

Nov 21 '05 #7
I get error on Me.GetType:

"'Me' is valid only within an instance method."

It have a console application, thats why?
/k

"Chris, Master of All Things Insignificant" <chris@No_Spam_ Please.com> wrote
in message news:eE******** ******@TK2MSFTN GP11.phx.gbl...
Dim p As System.Reflecti on.Assembly
p = System.Reflecti on.Assembly.Get ExecutingAssemb ly()
Icons(0) = New System.Drawing. Icon(p.GetManif estResourceStre am(Me.GetType() , "GreenBulb.ico" ))
Icons(1) = New System.Drawing. Icon(p.GetManif estResourceStre am(Me.GetType() , "YellowBulb.ico "))
Icons(2) = New System.Drawing. Icon(p.GetManif estResourceStre am(Me.GetType() , "RedBulb.ic o"))

Hope it helps
Chris

PS. Make sure you make the icons as embedded.

"kurt sune" <ap*@apa.cx> wrote in message
news:uW******** *****@TK2MSFTNG P12.phx.gbl...
Anybody has a tip of where to find info/example how to retrieve an icon
from a .RESX-file?

/k


Nov 21 '05 #8
I get error on Me.GetType:

"'Me' is valid only within an instance method."

It have a console application, thats why?
/k

"Chris, Master of All Things Insignificant" <chris@No_Spam_ Please.com> wrote
in message news:eE******** ******@TK2MSFTN GP11.phx.gbl...
Dim p As System.Reflecti on.Assembly
p = System.Reflecti on.Assembly.Get ExecutingAssemb ly()
Icons(0) = New System.Drawing. Icon(p.GetManif estResourceStre am(Me.GetType() , "GreenBulb.ico" ))
Icons(1) = New System.Drawing. Icon(p.GetManif estResourceStre am(Me.GetType() , "YellowBulb.ico "))
Icons(2) = New System.Drawing. Icon(p.GetManif estResourceStre am(Me.GetType() , "RedBulb.ic o"))

Hope it helps
Chris

PS. Make sure you make the icons as embedded.

"kurt sune" <ap*@apa.cx> wrote in message
news:uW******** *****@TK2MSFTNG P12.phx.gbl...
Anybody has a tip of where to find info/example how to retrieve an icon
from a .RESX-file?

/k


Nov 21 '05 #9
Wow, quite an improvement versus the old LoadResIcon("ic onname").

Thanks,
/k
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:#C******** ******@tk2msftn gp13.phx.gbl...
Kurt,
In addition to the other comments.

Rather then storing the icon in a .RESX file, I normally just embed the icon directly, as its easier to maintain.

Shawn's article shows how to embed the icon directly & retrieve it. Plus
explains why its easier to maintain.
http://www.windojitsu.com/blog/resxsucks.html

My Xml Resource Resolver was written with XML in mind, however it can easily be used with other resources, such as icons.
http://msmvps.com/jayharlow/archive/.../24/33766.aspx

To use my XmlResourceReso lver "as is" with an icon, use something like:

Public Module TestModule
Dim name As String
Dim resolver As New XmlResourceReso lver(GetType(Te stModule))
Dim absoluteUri As Uri = resolver.Resolv eUri(Nothing, name)
Dim input As Stream = DirectCast(reso lver.GetEntity( absoluteUri,
Nothing, Nothing), Stream)

Dim theIcon As New Icon(input)

End Module

Alternatively you could just extract most of the GetEntity method into its
own class (which gives you a class similar to Shawn's). Something like:

Option Strict On
Option Explicit On

Imports System.IO
Imports System.Globaliz ation
Imports System.Reflecti on

Public Class ResourceLoader

Private ReadOnly m_assembly As [Assembly]
Private ReadOnly m_type As Type

Public Sub New(ByVal type As Type)
m_assembly = type.Assembly
m_type = type
End Sub

Public ReadOnly Property Location() As String
Get
Return m_assembly.Loca tion
End Get
End Property

Public Function GetStream(ByVal name As String) As Stream
Dim culture As CultureInfo = CultureInfo.Cur rentUICulture
Dim stream As Stream

' Try the specific culture
stream = GetManifestReso urceStream(cult ure, name)

' Try the neutral culture
If stream Is Nothing AndAlso Not culture.IsNeutr alCulture Then
stream = GetManifestReso urceStream(cult ure.Parent, name)
End If

' Try the default culture
If stream Is Nothing Then
stream = GetManifestReso urceStream(name )
End If

If stream Is Nothing Then
Throw New FileNotFoundExc eption(Nothing, name)
End If
Return stream

End Function

Private Function GetManifestReso urceStream(ByVa l culture As CultureInfo, ByVal name As String) As Stream
Try
Dim satellite As [Assembly] =
m_assembly.GetS atelliteAssembl y(culture)
Return satellite.GetMa nifestResourceS tream(m_type, name)
Catch ex As FileNotFoundExc eption
Return Nothing
End Try
End Function

Private Function GetManifestReso urceStream(ByVa l name As String) As
Stream
Return m_assembly.GetM anifestResource Stream(m_type, name)
End Function

End Class

Hope this helps
Jay

"kurt sune" <ap*@apa.cx> wrote in message
news:uW******** *****@TK2MSFTNG P12.phx.gbl...
Anybody has a tip of where to find info/example how to retrieve an icon
from a .RESX-file?

/k


Nov 21 '05 #10

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

Similar topics

3
7572
by: Nils Erik Asmundvaag | last post by:
Hello I hope someone is able to help me with this frustrating problem. I have a C# web project in Visual Studio .NET 2003. I want to support Swedish and Norwegian texts and have put the texts in resource files (.resx). I build the project from the IDE without errors. A main assembly (containing the Swedish texts) are created, and a resource assembly
4
8598
by: Mehdi Mousavi | last post by:
Hi, I need to know how to extract a specific icon (32x32 for instance) from an icon file that contains more than one icon size? Any help would be highly appreciated, Cheers. Mehdi
0
1145
by: Steve Teeples | last post by:
Can someone tell me the proper way of adding an image to a RESX file via the IDE? I understand how text is added but I don't know how to add an icon or bitmap to the file. -- Steve
1
1938
by: Alvo von Cossel I | last post by:
hi, i have a resx file with an icon in it. 1. how do i make that icon the icon for the exe file? 2. when you change the icon for a folder (this only works with win xp) and click an .exe file, the icons stored in it appear. this doesnt happen with my exe file. do i need to do something different --
0
1677
by: Carl Mercier | last post by:
(I'm using C# 2.0) Hi, I have placed an icon file in resources.resx. The problem is that I don't know how to retrieve it. In VB.NET 2.0, My.Resources.MyIcon does the trick, but what's the C# equivalent? Unfortunately, what happens under the hood with the My namespace is not well documented. Reflector on Microsoft.VisualBasic.dll
0
298
by: kurt sune | last post by:
Anybody has a tip of where to find info/example how to retrieve an icon from a .RESX-file? /k
5
63806
by: João Santa Bárbara | last post by:
hi there i have this error in VS2005 DEV Edition "Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information." i have create an windows forms application (exe) and in the same project i have create 2 forms
4
6555
by: randy1200 | last post by:
I have a Windows application that previously had the company logo "MyCompany.ico" added to the upper left-most corner. The company has since issued a new version of "MyCompany.ico" that looks completely different. I overwrote the old ico file with the new ico file and re-ran the program. I still see the old logo at run-time. I right-clicked the project-> Add Existing Item-> added the new ico file. I set the build action to Embedded...
8
12090
by: John Dunn | last post by:
Since currently we aren't allowed to have compiled XAML files embedded in C++ apps I'm using Markup::XamlReader::Load to dynamically load XAML files. This works perfectly fine with external files but I'd like to be able to load a file specified in a .resx resource. I've added my .xaml file to the .resx and can load it in using ResourceManager::GetObject(). The object returned is a System::Array^ which contains System::Byte objects. The...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10049
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8873
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5309
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.