____________________________________________________________________
using System ;
using System.Collections.Generic ;
using System.ComponentModel ;
using System.Data ;
using System.Drawing ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
using System.Windows.Forms ;
namespace notepad
{
public partial class Form1 : Form
{
public bool a = false;
String filename = "";
public Form1()
{
InitializeComponent();
}
private void newToolStripMenuItem1_Click(object sender, EventArgs e)
{
if (a = false)
{
richTextBoxEx1.Text = "";
a = true;
filename = "";
}
else
{
DialogResult dr = MessageBox.Show("do you want to save?", "!!!", MessageBoxButtons.YesNoCancel);
if (dr == DialogResult.Yes)
{
saveToolStripMenuItem1_Click(null, null);
richTextBoxEx1.Text = "";
a = false;
filename = "";
}
else if (dr == DialogResult.No)
{
richTextBoxEx1.Text = "";
a = false;
filename = "";
}
}
}
private void fontToolStripMenuItem_Click(object sender, EventArgs e)
{
fontDialog1.ShowDialog();
richTextBoxEx1.Font = fontDialog1.Font;
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
private void openToolStripMenuItem1_Click(object sender, EventArgs e)
{
if (a = false)
{
openFileDialog1.ShowDialog();
try
{
String s = System.IO.File.ReadAllText(openFileDialog1.FileName);
richTextBoxEx1.Text = s;
}
catch (Exception)
{
throw;
}
a = false;
}
else
{
DialogResult dr = MessageBox.Show("do you want to save?", "!!!", MessageBoxButtons.YesNoCancel);
if (dr == DialogResult.Yes)
{
saveToolStripMenuItem1_Click(null, null);
openFileDialog1.ShowDialog();
try
{
String s = System.IO.File.ReadAllText(openFileDialog1.FileName);
richTextBoxEx1.Text = s;
}
catch (Exception)
{
throw;
}
a = false;
}
else if (dr == DialogResult.No)
{
openFileDialog1.ShowDialog();
try
{
String s = System.IO.File.ReadAllText(openFileDialog1.FileName);
richTextBoxEx1.Text = s;
}
catch (Exception)
{
throw;
}
a = false;
}
}
}
public void saveToolStripMenuItem1_Click(object sender, EventArgs e)
{
saveFileDialog1.ShowDialog();
try
{
System.IO.File.WriteAllText(saveFileDialog1.FileName, richTextBoxEx1.Text);
filename = saveFileDialog1.FileName;
}
catch (Exception)
{
throw;
}
a = false;
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
if (a = false)
{
Application.Exit();
}
else
{
DialogResult dr = MessageBox.Show("do you want to save?", "!!!", MessageBoxButtons.YesNoCancel);
if (dr == DialogResult.Yes)
{
saveToolStripMenuItem1_Click(null, null);
Application.Exit();
}
else if (dr == DialogResult.No)
{
Application.Exit();
}
}
}
private void richTextBoxEx1_TextChanged(object sender, EventArgs e)
{
a = true;
}
private void saveAsToolStripMenuItem1_Click(object sender, EventArgs e)
{
if( filename == "")
{
}
else
{
System.IO.File.WriteAllText(filename, richTextBoxEx1.Text);
}
}
}
}