您的位置:首页 > 编程语言 > C#

C#:C# 以前的一个简单的记事…

2014-06-12 13:51 471 查看
//当时不懂,如果谁看到这个文章,不要怪啊,我是写给自己看的

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 class
Form1 : Form
    {
     
  public Form1()
     
  {
     
     
InitializeComponent();
     
  }
     
  public void FileSave(string name)
     
  {
     
      try
     
      {
     
     
    textBox1.Text = textBox1.Text
+DateTime.Now;
     
     
    IFormatter formater = new
BinaryFormatter();
     
     
    Stream stream2 = new
FileStream(name, FileMode.Create, FileAccess.Write);
     
     
    formater.Serialize(stream2,
textBox1.Text);
     
     
    stream2.Close();
     
      }
     
      catch
(Exception ee)
     
      {
     
     
   
MessageBox.Show(ee.Message);
     
      }

     
  }

     
  public void FileOpen(string name)
     
  {
     
      IFormatter
formater1 = new BinaryFormatter();
     
      Stream
stream1 = new FileStream(name, FileMode.Open,
FileAccess.Read);
     
     
textBox1.Text = formater1.Deserialize(stream1).ToString();
     
     
stream1.Close();
     
  }

     
  private void 打开ToolStripMenuItem_Click(object
sender, 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(object
sender, EventArgs e)
     
  {
     
     
SaveFileDialog othersave = new SaveFileDialog();
     
     
othersave.Filter = "text文件|*.text";
     
     
othersave.ShowDialog();
     
      string
filename = othersave.FileName;
     
     
FileSave(filename);
     
     
MessageBox.Show("保存成功!");
     
  }

     
  private void 另存为ToolStripMenuItem_Click(object
sender, EventArgs e)
     
  {
     
     
SaveFileDialog othersave = new SaveFileDialog();
     
     
othersave.Filter = "text文件|*.text";
     
     
othersave.ShowDialog();
     
      string
filename = othersave.FileName;
     
     
FileSave(filename);
     
  }

     
  private void 关闭ToolStripMenuItem_Click(object
sender, EventArgs e)
     
  {
     
      if
(MessageBox.Show("确定要关闭文档?", "关闭文档", MessageBoxButtons.OKCancel,
MessageBoxIcon.Question) == DialogResult.OK)

     
      {
Application.Exit(); }
     
  }

     
  private void 颜色ToolStripMenuItem_Click(object
sender, EventArgs e)
     
  {
     
     
ColorDialog color = new ColorDialog();
     
      if
(color.ShowDialog() == DialogResult.OK)
     
      {
     
     
    textBox1.ForeColor =
color.Color;
     
      }
     
  }

     
  private void 字体ToolStripMenuItem1_Click(object
sender, EventArgs e)
     
  {
     
      FontDialog
font = new FontDialog();
     
      if
(font.ShowDialog() == DialogResult.OK)
     
      {
     
     
    textBox1.Font =
font.Font;
     
      }
     
  }
     
  private void 背景ToolStripMenuItem_Click(object
sender, EventArgs e)
     
  {
     
     
ColorDialog color = new ColorDialog();
     
      if
(color.ShowDialog() == DialogResult.OK)
     
      {
     
     
    textBox1.BackColor =
color.Color;
     
      }
     
  }

     
  private void 联系作者ToolStripMenuItem_Click(object
sender, EventArgs e)
     
  {
     
     
System.Diagnostics.Process.Start("http://652768664.qzone.qq.com");
     
  }

     
  private void Form1_Load(object sender, EventArgs
e)
     
  {
     
     
 label1.Text =
"系统当前时间:"+DateTime.Now.ToString();
     
  }

     
  private void 粘贴ToolStripMenuItem_Click(object
sender, EventArgs e)
     
  {
     
     
textBox1.Text=textBox1.Text+" "+Clipboard.GetText();
     
  }

     
  private void 清空文本ToolStripMenuItem_Click(object
sender, EventArgs e)
     
  {
     
     
textBox1.Text = "";
     
  }

     
  private void 全选ToolStripMenuItem_Click(object
sender, EventArgs e)
     
  {
     
     
textBox1.SelectAll();
     
  }

     
  private void 复制ToolStripMenuItem_Click(object
sender, EventArgs e)
     
  {
     
     
IDataObject copy = Clipboard.GetDataObject();
     
     
copy.GetDataPresent(DataFormats.Text);
     
  }

     
  

     
 
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: