First create a project for a Windows Forms application in Visual Studio.
Then open the Form1.cs GUI file and make the design with one MenuStrip, two TextBoxes and a Label and drag an openfileDialog, saveFileDialog, folderBrowserDialog, colorDialog and fontDialogs). Make one Menu as in the following:
Now we move to the code.
openFileDialog Click Event
- private void openDialogToolStripMenuItem_Click(object sender, EventArgs e)
- {
- openFileDialog1.Filter = "Text file (*.txt)|*.txt|All file(*.*)|*.*";
- if (openFileDialog1.ShowDialog() == DialogResult.OK)
- {
- stropen = openFileDialog1.FileName;
- textBox1.Text = System.IO.File.ReadAllText(stropen);
- }
- }
saveFileDialog Click Event
Write text in the TextBox area and then click on the Save menu option.
- private void saveDialogToolStripMenuItem_Click(object sender, EventArgs e)
- {
- saveFileDialog1.Filter = "Text file (*.txt)|*.txt|All file(*.*)|*.*";
- if (saveFileDialog1.ShowDialog() == DialogResult.OK)
- {
- strsave = saveFileDialog1.FileName;
- System.IO.File.WriteAllText(strsave, textBox1.Text);
- }
- }
fontDialog Click Event
- private void fontDialogToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (fontDialog1.ShowDialog() == DialogResult.OK)
- {
- textBox1.Font = fontDialog1.Font;
- textBox1.ForeColor = fontDialog1.Color;
-
- }
- }
colorDialog Click Event
- private void colorDialogToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (colorDialog1.ShowDialog() == DialogResult.OK)
- {
-
-
- textBox1.BackColor = colorDialog1.Color;
- }
- }
browserDialog Click Event
- private void browseDialogToolStripMenuItem_Click(object sender, EventArgs e)
- {
- folderBrowserDialog1.RootFolder = Environment.SpecialFolder.Desktop;
- if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
- {
- textBox2.Text = folderBrowserDialog1.SelectedPath;
- }
- }
Thank you.