473,785 Members | 2,736 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
15 3650
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 #11
In your code
"Return MyBase.ResolveU ri(baseUri, relativeUri)"

I get errror:
"'MyBase' cannot be used with method 'Public Overridable MustOverride
Overloads Function ResolveUri(base Uri As System.Uri, relativeUri As String)
As System.Uri' because it is declared 'MustOverride'. "

Ideas?

/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.
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

Nov 21 '05 #12
In your code
"Return MyBase.ResolveU ri(baseUri, relativeUri)"

I get errror:
"'MyBase' cannot be used with method 'Public Overridable MustOverride
Overloads Function ResolveUri(base Uri As System.Uri, relativeUri As String)
As System.Uri' because it is declared 'MustOverride'. "

Ideas?

/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.
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

Nov 21 '05 #13
Kurt,
BTW: If you want to keep the Icon in a .resx file, you can use a
System.Resource s.ResourceManag er to read it.

There are advantages to both.

Hope this helps
Jay

"kurt sune" <ap*@apa.cx> wrote in message
news:O$******** ******@TK2MSFTN GP11.phx.gbl...
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 #14
Kurt,
BTW: If you want to keep the Icon in a .resx file, you can use a
System.Resource s.ResourceManag er to read it.

There are advantages to both.

Hope this helps
Jay

"kurt sune" <ap*@apa.cx> wrote in message
news:O$******** ******@TK2MSFTN GP11.phx.gbl...
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 #15
kurt,
Which version of .NET?

The code posted & on my blog works in VS.NET 2003 (.NET 1.1).

I noticed my blog page, has "cut & paste" issues, are you certain you got
the code to look like my blog page?

Hope this helps
Jay

"kurt sune" <ap*@apa.cx> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
In your code
"Return MyBase.ResolveU ri(baseUri, relativeUri)"

I get errror:
"'MyBase' cannot be used with method 'Public Overridable MustOverride
Overloads Function ResolveUri(base Uri As System.Uri, relativeUri As
String)
As System.Uri' because it is declared 'MustOverride'. "

Ideas?

/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.
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


Nov 21 '05 #16

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
8599
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
63809
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
6557
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
12091
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
10319
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
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
8971
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
7496
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
6737
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5380
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4046
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
3
2877
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.