Resource Files

  • Thread starter Thread starter Guy
  • Start date Start date
G

Guy

Hi,
Does anyone know ho to use a .resx file for storing and retrieving bitmaps?
Thanks.
 
Unless you really need to use a .resx file, you might want to try the code
below instead. Add any bitmap or icon files directly to your project, make
them embedded resources, list their names in the enums (they must be exact),
and replace "LocalAssemblyName".

Bob

--------------

Imports System.Reflection

Public Class Resources

Private Sub New()
End Sub

Public Enum Icons
IconFileName1
IconFileName2
IconFileName3
End Enum

Public Enum Images
ImageFileName1
ImageFileName2
ImageFileName3
End Enum

Public Shared Function GetIcon(ByVal Icon As Icons) As Icon
Dim ret As Icon
Dim asm As [Assembly] = [Assembly].GetExecutingAssembly
Dim Name As String = "LocalAssemblyName." & _
System.Enum.GetName(Icon.GetType, Icon) & ".ico"
Dim s As System.IO.Stream = asm.GetManifestResourceStream(Name)
If Not s Is Nothing Then
ret = New Icon(s)
s.Close()
End If
Return ret
End Function

Public Shared Function GetImage(ByVal Image As Images) As Image
Dim ret As Image
Dim asm As [Assembly] = [Assembly].GetExecutingAssembly
Dim Name As String = "LocalAssemblyName." & _
System.Enum.GetName(Image.GetType, Image) & ".bmp"
Dim s As System.IO.Stream = asm.GetManifestResourceStream(Name)
If Not s Is Nothing Then
ret = New Bitmap(s)
s.Close()
End If
Return ret
End Function

End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top