How Display Icon on Picture Box from Resource File
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: How Display Icon on Picture Box from Resource File

  1. #1
    Join Date
    May 2012
    Posts
    1

    How Display Icon on Picture Box from Resource File

    Hi,
    I am working on a Vb6 to VB.net migration application.I am not able to proceed in one place.I have a Resources.Resx file in my application in which some Icons are stored like "icoUS","icoCA" etc. And there is a combo box where some country names are listed.On selection of this combo box, the corresponding countrie's flag image should be dsiplayed on a picture box. Any help appreciated in this regard. The code , which I used is given below.
    Code:
    Imports System.Resources
    Public Class Form1
    
        Private Sub lstCountries_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstCountries.SelectedIndexChanged
            Dim cntryCode As String = String.Empty
    
            If lstCountries.SelectedItem = "Australlia" Then
                cntryCode = "AU"
            ElseIf lstCountries.SelectedItem = "Brazil" Then
                cntryCode = "BR"
            ElseIf lstCountries.SelectedItem = "Canada" Then
                cntryCode = "CA"
            ElseIf lstCountries.SelectedItem = "Denmark" Then
                cntryCode = "DE"
            ElseIf lstCountries.SelectedItem = "United States" Then
                cntryCode = "US"
            End If
    
            Dim img As String = "ico" & cntryCode
            picImage.Image = CType(My.Resources.ResourceManager.GetObject(img), Image)
    
    
            'Dim res() As String = GetType(Form1).Assembly.GetManifestResourceNames()
            ' picImage.Image = New System.Drawing.Bitmap(GetType(ImageTest.My.Resources.Resource1).Assembly.GetManifestResourceStream(res(0)))
        End Sub
    
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            picImage.Visible = True
        End Sub
    End Class

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,999

    Re: How Display Icon on Picture Box from Resource File

    0 is the first entry. You'll need the .SelectedIndex value (Proper Type necessary)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center