Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleLoad resources from another Assembly in VB .NET
DescriptionThis example shows how to load resources from another Assembly in VB .NET.
Keywordsresources, Assembly, VB .NET
CategoriesVB.NET
 
When the user clicks the List button, the program initializes an Assembly object representing the target Assembly. It then loops through the names returned by the Assembly's GetManifestResourceNames method and adds them to a ListBox.
 
Private m_TargetAssembly As System.Reflection.Assembly

' List the target assembly's resources.
Private Sub btnList_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnList.Click
    Me.Cursor = Cursors.WaitCursor
    Application.DoEvents()

    ' Get the target assembly.
    m_TargetAssembly = _
        System.Reflection.Assembly.LoadFile(txtFile.Text)

    ' List the target's manifest resource names.
    lstResources.Items.Clear()
    For Each str As String In _
        m_TargetAssembly.GetManifestResourceNames()
        lstResources.Items.Add(str)
    Next str

    Me.Cursor = Cursors.Default
End Sub
 
When the user clicks an item in the ListBox, the program examines the resource's extension. If the resource is an image, the program uses the Assembly's GetManifestResourceStream method to get the resource in a Stream. It uses the Stream to create a Bitmap and displays the result.
 
' Display the selected resource.
Private Sub lstResources_SelectedIndexChanged(ByVal sender _
    As System.Object, ByVal e As System.EventArgs) Handles _
    lstResources.SelectedIndexChanged
    If lstResources.SelectedItem Is Nothing Then Exit Sub

    ' Load a Bitmap from the resource stream.
    Dim resource_name As String = _
        lstResources.SelectedItem.ToString
    Dim extension As String = _
        resource_name.Substring(resource_name.LastIndexOf("."))
    Select Case extension.ToLower
        Case ".bmp", ".jpg", ".jpeg", ".gif"
            Dim bm As New Bitmap( _
                m_TargetAssembly.GetManifestResourceStream(resource_name))
            picImage.Image = bm
        Case Else
            picImage.Image = Nothing
    End Select
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated