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

//当时不懂,如果谁看到这个文章,不要怪啊,我是写给自己看的

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);
        }

         

       
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值