47 lines
1.4 KiB
C#
Executable File
47 lines
1.4 KiB
C#
Executable File
namespace lab5_4_CalebFontenot
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void writeNameButton_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
// Declare a StreamWriter Variable.
|
|
StreamWriter outputFile;
|
|
saveFile.ShowDialog();
|
|
// Open the 'Friend.txt' file for appending,
|
|
// and get a StreamWriter object.
|
|
outputFile = File.AppendText(saveFile.FileName);
|
|
|
|
// Append the friend's name to the file.
|
|
outputFile.WriteLine(nameTextBox.Text);
|
|
|
|
// Close the file.
|
|
outputFile.Close();
|
|
|
|
// Let the user know the name was written.
|
|
MessageBox.Show("Wrote \"" + nameTextBox.Text + "\" to file.");
|
|
|
|
// Clear the nameTextBox control.
|
|
nameTextBox.Text = "";
|
|
|
|
// Give the focus to the nameTextBox control.
|
|
nameTextBox.Focus();
|
|
|
|
} catch (Exception ex) {
|
|
// Display an error message.
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
}
|
|
|
|
private void exitButton_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
}
|
|
} |