记事本的部分代码

    技术2022-05-19  23

    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)