private void 新建ToolStripMenuItem_Click(object sender, EventArgs e) { if (IsChange == true) { SaveTF tf; if (Path == "") { tf = new SaveTF(); } else { tf = new SaveTF(Path + "\\" + FileName); } tf.ShowDialog(); if (tf.DialogResult == DialogResult.OK) { //保存ToolStripMenuItem_Click(sender, e); } if (tf.DialogResult == DialogResult.Cancel) { return; } } textBox1.Text = ""; Path = ""; IsChange = false; FileName = "记事本"; this.Text = FileName; }
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e) { if (IsChange == true) { SaveTF tf; if (Path == "") { tf = new SaveTF(); } else { tf = new SaveTF(Path + "\\" + FileName); } tf.ShowDialog(); if (tf.DialogResult == DialogResult.OK) { 保存ToolStripMenuItem_Click(sender, e); } if (tf.DialogResult == DialogResult.Cancel) { return; } } OpenFileDialog open = new OpenFileDialog(); open.Filter = "文本文件|*.txt"; if (open.ShowDialog() == DialogResult.OK) { FileName = open.FileName.Substring(open.FileName.LastIndexOf('\\') + 1); Path = open.FileName.Substring(0, open.FileName.Length - FileName.Length - 1); textBox.Text = OpenFile(open.FileName); this.Text = FileName; } }
void OpenTxt() { if (IsChange == true) { SaveTF tf; if (Path == "") { tf = new SaveTF(); } else { tf = new SaveTF(Path + "\\" + FileName); } tf.ShowDialog(); if (tf.DialogResult == DialogResult.OK) { //保存ToolStripMenuItem_Click(sender, e); } if (tf.DialogResult == DialogResult.Cancel) { return; } } OpenFileDialog open = new OpenFileDialog(); string patch = Application.StartupPath + "\\LOG\\"; open.InitialDirectory = patch; open.Filter = "文本文件|*.txt"; if (open.ShowDialog() == DialogResult.OK) { if (open.FileName != "") { Path = open.FileName; //显示文本文件内容 textBox.Text = File.ReadAllText(Path); //获取文件标题 NoteName.Text = open.FileName.Substring(open.FileName.LastIndexOf('\\') + 1); } } }
private void txt_FormClosing(object sender, FormClosingEventArgs e) { if (IsChange == true) { SaveTF tf; if (Path == "") { tf = new SaveTF(); } else { tf = new SaveTF(Path + "\\" + FileName); } tf.ShowDialog(); if (tf.DialogResult == DialogResult.OK) { 保存ToolStripMenuItem_Click(sender, e); } if (tf.DialogResult == DialogResult.Cancel) { e.Cancel = true; } } }