C# 记事本查找替换 新手 请高人多多指教

这是一个C#实现的记事本应用程序,包含打开、保存、新建、打印、查找和替换等功能。用户可以加载文本文件,编辑内容,并通过查找对话框进行文本搜索和替换操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//主窗体部分

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.Drawing.Printing;

 

 

namespace notepad
{
    public partial class Form1 : Form
    {
        public string path="";
        public string wenben;
        public bool saved;
        System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();
        public Form1()
        {
            InitializeComponent();
             //  richTextBox1.Size.Width = this.Size.Width;
            //    richTextBox1.Size.Height = this.Size.Height;
            saved = false ;
           this.Paint+=new PaintEventHandler(Form1_Paint);
            this.FormClosing+=new FormClosingEventHandler(Form1_FormClosing);
           //richTextBox1.b;
        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
            wenben = richTextBox1.Text;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.toolStripStatusLabel1.Text = "当前时间为   "+DateTime.Now.ToShortTimeString();
            this.toolStripStatusLabel2.Text= "20082121003 鲍东升制作";
            this.toolStripStatusLabel3.Text = "         软件综合课程设计";
            printPreviewControl1.Document = pd;
           
        }
       
        private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "*.txt(文本文档)|*.txt";
            if(openFileDialog1.ShowDialog()==DialogResult.OK)
            {
                StreamReader SReader=new StreamReader(openFileDialog1.FileName,Encoding.Default);
                richTextBox1.Text = SReader.ReadToEnd();
               // richTextBox1.Font = SReader.;
                SReader.Close();
                path = openFileDialog1.FileName;
               
            }
            this.Text = openFileDialog1.SafeFileName;
         //   richTextBox1.LoadFile(path);
         //   MessageBox.Show(path);
        }

        private void 另存为ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            saveFileDialog1.Filter = "*.txt(文本文档)|*.txt";
            if(saveFileDialog1.ShowDialog()==DialogResult.OK)
            {
                StreamWriter SWriter = new StreamWriter(saveFileDialog1.FileName, true);
                SWriter.Write(richTextBox1.Text);
                SWriter.Close();
            }
            saved = true;
        }

        private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            saveFileDialog1.DefaultExt = "*.txt";
       //     RichTextBoxStreamType = "*.txt";
            if (path.Length > 0)
            {


                richTextBox1.SaveFile(path, RichTextBoxStreamType.TextTextOleObjs);
                //      MessageBox.Show(path);
            }
            else
            {
                saveFileDialog1.Filter = "*.txt(文本文档)|*.txt"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值