Since this is some form of homework I will give you code in C#.
- One listBox named CountryListBox
- One PictureBox
Create a folder named images, place your images in there and follow the code below. This way you have direction.
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace CountryImages
{
/// <summary>
/// Create a folder named Images, place each country image in this folder
/// Add an blank image named 0.bmp or 0.png, set copy to output directory
/// to copy if newer
///
/// Operation class in VB.NET would be a code module
///
/// Each class should be in a separate file.
///
/// </summary>
public partial class Form1 : Form
{
private readonly BindingSource bindingSource = new BindingSource();
public Form1()
{
InitializeComponent();
Shown += OnShown;
}
private void OnShown(object sender, EventArgs e)
{
bindingSource.DataSource = Operations.GetCountries();
CountryListBox.DataSource = bindingSource;
pictureBox1.DataBindings.Add("Image", bindingSource, "Image");
}
}
public class Country
{
public string Name { get; set; }
public Image Image { get; set; }
public override string ToString() => Name;
}
public class Operations
{
public static List<Country> GetCountries()
{
List<Country> list = new List<Country>();
var files = Directory.GetFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Images"));
foreach (var file in files)
{
Country country = new Country
{
Name = Path.GetFileNameWithoutExtension(file),
Image = Image.FromFile(file)
};
list.Add(country);
}
list.FirstOrDefault().Name = "Select";
return list;
}
}
}
And note the creating the list above can be done in less code
public class Operations
{
public static List<Country> GetCountries()
{
var files = Directory.GetFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Images"));
List<Country> list = files.Select(file => new Country { Name = Path.GetFileNameWithoutExtension(file), Image = Image.FromFile(file) }).ToList();
list.FirstOrDefault().Name = "Select";
return list;
}
}