C-Sharp-Moment
This commit is contained in:
49
lab5_3/lab5_6_CalebFontenot/Form1.cs
Executable file
49
lab5_3/lab5_6_CalebFontenot/Form1.cs
Executable file
@@ -0,0 +1,49 @@
|
||||
namespace lab5_6_CalebFontenot
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void getCountriesButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Declare a variable to hold a country name.
|
||||
string countryName;
|
||||
|
||||
// Declare a StreamReader variable.
|
||||
StreamReader inputFile;
|
||||
|
||||
// Open the file and get a StreamReader object.
|
||||
inputFile = File.OpenText("Countries.txt");
|
||||
|
||||
// Clear anything currently in the ListBox.
|
||||
countriesListBox.Items.Clear();
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
private void exitButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user