41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
|
namespace Lab5_9_CalebFontenot
|
||
|
{
|
||
|
public partial class Form1 : Form
|
||
|
{
|
||
|
public Form1()
|
||
|
{
|
||
|
InitializeComponent();
|
||
|
}
|
||
|
|
||
|
private void Form1_Load(object sender, EventArgs e)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
// Declare a variable to load a country name.
|
||
|
string countryName;
|
||
|
|
||
|
// Declare a StreamReader variable.
|
||
|
StreamReader inputFile;
|
||
|
|
||
|
// Open the file and get a StreamReader object.
|
||
|
inputFile = File.OpenText("Countries.txt");
|
||
|
|
||
|
// Read the file's contents
|
||
|
while (!inputFile.EndOfStream)
|
||
|
{
|
||
|
// Get a country name.
|
||
|
countryName = inputFile.ReadLine();
|
||
|
|
||
|
//Add the country name to the ListBox.
|
||
|
countriesListBox.Items.Add(countryName);
|
||
|
}
|
||
|
// Close the file.
|
||
|
inputFile.Close();
|
||
|
} catch (Exception ex)
|
||
|
{
|
||
|
//Display an error message.
|
||
|
MessageBox.Show(ex.Message);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|