pictureboxes RRS feed

  • Question

  • I'm doing a form for countries and stuff. when i choose a country i would like for the countries flag to be displayed. i have an array of countries and the flags in a folder. how can i display these flags at the same time?

    all answers welcome, as usual

    thanks all


    Monday, February 19, 2007 7:47 PM


  • You could keep seperate arrays of country-names and flags, but it would be easier if you made a type of object that contained both name + flag (+ other stuff) and then have one array that contained all the custom-made objects. Here's an example (You could use a Class, but I'm using a Structure here):

    Public Class Form1

        '   Define a Structure as a custom-made "Country" type:
        Private Structure Country
            Public Name As String
            Public Flag As Bitmap
        End Structure

        '   the zCountries ArrayList will hold all the Country objects
        Private zCountries As New ArrayList

        Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click

            '   Create a new Country and fill in the Name and Flag settings
            Dim zCountry As Country
            zCountry.Name = "MicrosoftLand"
            zCountry.Flag = Bitmap.FromFile("C:\FlagFolder\CrossOfSaintGatesAndBallmer.png")

            '   Add the new Country to the collection of Countries

            '   Now display the Country's information
            '   (
    MicrosoftLand is the first item, at index 0 inside the ArrayList)
            Dim theCountry As Country = zCountries.Item(0)
            Me.Text = theCountry.Name
            Me.BackgroundImage = theCountry.Flag

        End Sub
    End Class
    Monday, February 19, 2007 8:23 PM