记事本代码
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 WindowsFormsApp3
{
public partial class frmNotepad : Form
{
bool b = false;
bool s = true;
public frmNotepad()
{
InitializeComponent();
}
private void rtxtNotepad_TextChanged(object sender, EventArgs e)
{
s = false;
}
private void tsmiOpen_Click(object sender, EventArgs e)
{
if (b == true || rtxtNotepad.Text.Trim() != "")
{
if (s == false)
{
string result;
result = MessageBox.Show("文件尚未保存,是否保存?","保存文件", MessageBoxButtons.YesNoCancel).ToString();
switch (result)
{
case "Yes":
if (b == true)
{
rtxtNotepad.SaveFile(odlgNotepad.FileName);
}
else if (sdlgNotepad.ShowDialog() == DialogResult.OK)
{
rtxtNotepad.SaveFile(sdlgNotepad.FileName);
}
s = true;
break;
case "No":
b = false;
rtxtNotepad.Text = "";
break;
}
}
}
odlgNotepad.RestoreDirectory = true;
if ((odlgNotepad.ShowDialog() == DialogResult.OK) && odlgNotepad.FileName != "")
{
rtxtNotepad.LoadFile(odlgNotepad.FileName);