G
Guest
Thought the group might be interested in the following class(modified from an
example I found on this newsgroup) for using embedded resources such as
icons, bitmaps, etc. Suppose you add an icon named "Icon1" to a project and
embed it in the project by select "embedded Resource" from right clicking on
the icon1.ico in the solution Explorer listing. The following class can be
used to retrieve the icon image for use in the project:
'Retrieve the embedded icon
dim r as new resource
dim ic as icon
ic = r.GetIcon("Icon1")
'Resource Class
Imports System.Reflection
Public Class Resources
Shared v_AssemblyName As String
Shared initialize As Boolean
Public Sub New()
If Not initialize Then
Dim thisExe As System.Reflection.Assembly = _
System.Reflection.Assembly.GetExecutingAssembly()
v_AssemblyName = thisExe.GetName.Name & "."
initialize = True
End If
End Sub
Public Function GetIcon(ByVal IconName As String) As Icon
Dim asm As [Assembly] = [Assembly].GetExecutingAssembly
Dim Name As String = v_AssemblyName & IconName & ".ico"
Dim s As System.IO.Stream = asm.GetManifestResourceStream(Name)
If Not s Is Nothing Then
Return New Icon(s)
s.Close()
Else
Return Nothing
End If
End Function
Public Function GetImage(ByVal ImageName As String) As Image
Dim asm As [Assembly] = [Assembly].GetExecutingAssembly
Dim Name As String = v_AssemblyName & ImageName & ".bmp"
Dim s As System.IO.Stream = asm.GetManifestResourceStream(Name)
If Not s Is Nothing Then
Return New Bitmap(s)
s.Close()
Else
Return Nothing
End If
End Function
End Class
example I found on this newsgroup) for using embedded resources such as
icons, bitmaps, etc. Suppose you add an icon named "Icon1" to a project and
embed it in the project by select "embedded Resource" from right clicking on
the icon1.ico in the solution Explorer listing. The following class can be
used to retrieve the icon image for use in the project:
'Retrieve the embedded icon
dim r as new resource
dim ic as icon
ic = r.GetIcon("Icon1")
'Resource Class
Imports System.Reflection
Public Class Resources
Shared v_AssemblyName As String
Shared initialize As Boolean
Public Sub New()
If Not initialize Then
Dim thisExe As System.Reflection.Assembly = _
System.Reflection.Assembly.GetExecutingAssembly()
v_AssemblyName = thisExe.GetName.Name & "."
initialize = True
End If
End Sub
Public Function GetIcon(ByVal IconName As String) As Icon
Dim asm As [Assembly] = [Assembly].GetExecutingAssembly
Dim Name As String = v_AssemblyName & IconName & ".ico"
Dim s As System.IO.Stream = asm.GetManifestResourceStream(Name)
If Not s Is Nothing Then
Return New Icon(s)
s.Close()
Else
Return Nothing
End If
End Function
Public Function GetImage(ByVal ImageName As String) As Image
Dim asm As [Assembly] = [Assembly].GetExecutingAssembly
Dim Name As String = v_AssemblyName & ImageName & ".bmp"
Dim s As System.IO.Stream = asm.GetManifestResourceStream(Name)
If Not s Is Nothing Then
Return New Bitmap(s)
s.Close()
Else
Return Nothing
End If
End Function
End Class