//当时不懂,如果谁看到这个文章,不要怪啊,我是写给自己看的
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
namespace 记事本_尝试版_
{
public partial classForm1 : Form
{
public Form1()
{
InitializeComponent();
}
public void FileSave(string name)
{
try
{
textBox1.Text = textBox1.Text+DateTime.Now;
IFormatter formater = newBinaryFormatter();
Stream stream2 = newFileStream(name, FileMode.Create, FileAccess.Write);
formater.Serialize(stream2,textBox1.Text);
stream2.Close();
}
catch(Exception ee)
{
MessageBox.Show(ee.Message);
}
}
public void FileOpen(string name)
{
IFormatterformater1 = new BinaryFormatter();
Streamstream1 = new FileStream(name, FileMode.Open,FileAccess.Read);
textBox1.Text = formater1.Deserialize(stream1).ToString();
stream1.Close();
}
private void 打开ToolStripMenuItem_Click(objectsender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.InitialDirectory = @"..\\";
open.Filter = "text文件|*.text";
if(open.ShowDialog() == DialogResult.OK)
{
FileOpen(open.FileName.ToString());
}
}
private void 保存ToolStripMenuItem_Click(objectsender, EventArgs e)
{
SaveFileDialog othersave = new SaveFileDialog();
othersave.Filter = "text文件|*.text";
othersave.ShowDialog();
stringfilename = othersave.FileName;
FileSave(filename);
MessageBox.Show("保存成功!");
}
private void 另存为ToolStripMenuItem_Click(objectsender, EventArgs e)
{
SaveFileDialog othersave = new SaveFileDialog();
othersave.Filter = "text文件|*.text";
othersave.ShowDialog();
stringfilename = othersave.FileName;
FileSave(filename);
}
private void 关闭ToolStripMenuItem_Click(objectsender, EventArgs e)
{
if(MessageBox.Show("确定要关闭文档?", "关闭文档", MessageBoxButtons.OKCancel,MessageBoxIcon.Question) == DialogResult.OK)
{Application.Exit(); }
}
private void 颜色ToolStripMenuItem_Click(objectsender, EventArgs e)
{
ColorDialog color = new ColorDialog();
if(color.ShowDialog() == DialogResult.OK)
{
textBox1.ForeColor =color.Color;
}
}
private void 字体ToolStripMenuItem1_Click(objectsender, EventArgs e)
{
FontDialogfont = new FontDialog();
if(font.ShowDialog() == DialogResult.OK)
{
textBox1.Font =font.Font;
}
}
private void 背景ToolStripMenuItem_Click(objectsender, EventArgs e)
{
ColorDialog color = new ColorDialog();
if(color.ShowDialog() == DialogResult.OK)
{
textBox1.BackColor =color.Color;
}
}
private void 联系作者ToolStripMenuItem_Click(objectsender, EventArgs e)
{
System.Diagnostics.Process.Start("http://652768664.qzone.qq.com");
}
private void Form1_Load(object sender, EventArgse)
{
label1.Text ="系统当前时间:"+DateTime.Now.ToString();
}
private void 粘贴ToolStripMenuItem_Click(objectsender, EventArgs e)
{
textBox1.Text=textBox1.Text+" "+Clipboard.GetText();
}
private void 清空文本ToolStripMenuItem_Click(objectsender, EventArgs e)
{
textBox1.Text = "";
}
private void 全选ToolStripMenuItem_Click(objectsender, EventArgs e)
{
textBox1.SelectAll();
}
private void 复制ToolStripMenuItem_Click(objectsender, EventArgs e)
{
IDataObject copy = Clipboard.GetDataObject();
copy.GetDataPresent(DataFormats.Text);
}
}
}