记事本的部分代码

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;

namespace 记事本
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saf = new SaveFileDialog();
            saf.Filter = "文本文件(*.txt)|*.txt|所有文件|*.*|所有执行的文件|*.exe";
            if (saf.ShowDialog() == DialogResult.OK)
            {
                StreamWriter sw = new StreamWriter(saf.FileName, false);
                sw.Write(textBox1.Text);
                sw.Flush();
                sw.Close();
            }
        }

        private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "文本文件(*.txt)|*.txt";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = "";
                StreamReader sr = new StreamReader(ofd.FileName);
                string str = sr.ReadToEnd();
                textBox1.Text = str;
                sr.Close();
            }
        }

        private void 字体ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FontDialog fd = new FontDialog();
            fd.Font = textBox1.Font;
            if (fd.ShowDialog() == DialogResult.OK)
            {
                 textBox1.Font=fd.Font ;
            }

        }

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

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            int x = this.Location.X;
            int y = this.Location.Y;
            int w = this.Size.Width;
            int h = this.Size.Height;
            string filePath = Application.StartupPath + "//system.dll";
            StreamWriter sw = new StreamWriter(filePath, false);
            sw.WriteLine(x);
            sw.WriteLine(y);
            sw.WriteLine(w);
            sw.WriteLine(h);
            sw.WriteLine(textBox1.ForeColor.R);
            sw.WriteLine(textBox1.ForeColor.G);
            sw.WriteLine(textBox1.ForeColor.B);
            sw.Close();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string fileName = Application.StartupPath + "//system.dll";
            if (File.Exists(fileName))
            {


                StreamReader sr = new StreamReader(fileName);
                int x = Convert.ToInt32(sr.ReadLine());
                int y = Convert.ToInt32(sr.ReadLine());
                int w = Convert.ToInt32(sr.ReadLine());
                int h = Convert.ToInt32(sr.ReadLine());
                int r = Convert.ToInt32(sr.ReadLine());
                int g = Convert.ToInt32(sr.ReadLine());
                int b = Convert.ToInt32(sr.ReadLine());

                Color c = Color.FromArgb(r, g, b);
                this.textBox1.ForeColor = c;

                this.Location = new Point(x, y);
                this.Size = new Size(w, h);
                sr.Close();
            }

        }

        private void 撤销ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Undo();
        }

        private void 复制ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Copy();
        }

        private void 粘贴ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Paste();
        }

        private void 剪切ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Cut();
        }

        private void 时间日期ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Text = DateTime.Now.ToString();
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
           
        }

        private void 自动换行ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.WordWrap.ToString();
        }

        private void 关于记事本ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form2 f = new Form2();
            f.Show();
        }

        private void 查找ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form3 f = new Form3();
            f.Show();
           
        }

   
    }
}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值