c#记事本的问题
程序代码:using System;
using System.Collections.Generic;
using using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using namespace 记事本
{
public partial class Form1 : Form
{
private string pathName = null;
private string SelectText = null;
private int ChangeText = 0;
public enum TextChang { NoChang, Chang }
public Form1()
{
InitializeComponent();
}
}
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
StreamReader sr = new StreamReader(openFileDialog1.FileName);
textmain.Text = sr.ReadToEnd();
sr.Close();
}
private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
{if(pathName==null)
{另存为toolStripMenuItem_Click(sender, e);}
else{textmain.SaveFile(pathName,RichTextBoxStreamType.PlainText);
}
//saveFileDialog1.ShowDialog();
//StreamWriter aw = new StreamWriter(saveFileDialog1.FileName);
//aw.Write(textmain.Text);
//aw.Close();只有保存时
}
private void 另存为toolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog sfDlg = new SaveFileDialog();
sfDlg.Filter = "文本文档(*.txt)|*.txt|所有文件(*.*)|*.*";
if (sfDlg.ShowDialog() == DialogResult.OK)
{
pathName = sfDlg.FileName;
textmain.SaveFile(sfDlg.FileName, RichTextBoxStreamType.PlainText);
this.Text = Path.GetFileName(pathName);
}
}
}
为什么点击打开以后,不选取文件点取消,程序会故障??








