Embedded Resources How To

In VB6, it was easy to add bitmaps, icons, strings, etc. to the resource file during design time.  The resources were read back during runtime using the LoadRes* functions.

I'm finding it difficult to find information which describe how to do this in VB.NET.

What are the steps and tools involved to get static resources added to the project?

Pointers to tutorials, articles, or even a step-by-step how to would be great.
LVL 32
Erick37Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

planoczCommented:
Sample ....


'FORM 1

Imports System.io
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        components = New System.ComponentModel.Container
        Me.Text = "Form1"
    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim executing_assembly As System.Reflection.Assembly = Me.GetType.Assembly.GetEntryAssembly()

        ' Get the namespace.
        Dim my_namespace As String = executing_assembly.GetName().Name.ToString()


        'Load image to a dynamically created picture box.

        Dim picture_stream As Stream
        Dim bm As Bitmap

        picture_stream = executing_assembly.GetManifestResourceStream(my_namespace + ".1040.ico") '<--to your icon image example

        If Not (picture_stream Is Nothing) Then
            bm = New Bitmap(picture_stream)
            Dim pict As New PictureBox
            pict.Image = bm
            pict.Top = 5
            pict.Left = 5
            pict.Height = 50
            pict.Width = 50
            pict.Visible = True
            Me.Controls.Add(pict)
            picture_stream.Close()
        End If



        'Load text to a dynamically created Label.

        Dim text_stream As Stream = executing_assembly.GetManifestResourceStream(my_namespace _
                   + ".Test.txt")   '<--- a text file example
        If Not (text_stream Is Nothing) Then
            Dim stream_reader As New StreamReader(text_stream)
            Dim lbl As New Label
            lbl.Text = stream_reader.ReadToEnd()
            lbl.Top = 75
            lbl.Left = 5
            lbl.Width = 500
            lbl.Height = 500
            lbl.Visible = True
            Me.Controls.Add(lbl)
            stream_reader.Close()
        End If

    End Sub
End Class


With pic item change the Build Action = embedded resource

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Erick37Author Commented:
Is there not a .NET equivalent of the VB6 Resource Editor?
Are string tables not supported?
What's the best way to manage 100 or 1000 strings?
planoczCommented:
As far as I know there is no .NET equivalent of the VB6 Resource Editor.

string tables or just text files?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.