The .NET framework has a series of built-in dialog boxes that can be used in applications. All of the functionality that you need is there and it makes sense to know how to use them. Fortunately, it's pretty easy.
Start by knocking up a form that looks like the one in the screenshot.
The buttons are named, btnOpen, btnSave and btnFont and the textbox is left at textBox1.
We are using the IO library here so add a using System.IO; at the top of the form.
private void btnOpen_Click(object sender, EventArgs e)
{
OpenFileDialog openDialog = new OpenFileDialog();
openDialog.Title = "Save A File";
openDialog.Filter = "Text Files (*.txt)|*.txt|HTML Files (*.htm)|*.htm";
if (openDialog.ShowDialog() == DialogResult.OK)
{
textBox1.Text = File.ReadAllText(openDialog.FileName);
}
}
We set the Title and Filter properties before we call the function to show the dialog.
private void btnSave_Click(object sender, EventArgs e)
{
SaveFileDialog saveDialog = new SaveFileDialog();
saveDialog.Title = "Save A File";
saveDialog.Filter = "Text Files (*.txt)|*.txt|HTML Files (*.htm)|*.htm";
if (saveDialog.ShowDialog() == DialogResult.OK)
{
File.WriteAllText(saveDialog.FileName, textBox1.Text);
}
}
private void btnFont_Click(object sender, EventArgs e)
{
FontDialog fDialog = new FontDialog();
if (fDialog.ShowDialog() == DialogResult.OK)
{
textBox1.Font = fDialog.Font;
}
}