• 大小: 271KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-29
  • 语言: C#
  • 标签: c#Editor  

资源简介

包含全部源码; 该文档编辑器,基本功能: 文件操作: 新建,打开,保存,退出;       //支持rtf文件 编辑操作: 复制,剪切,粘贴,全选; 查找与替换: 设计查找(替换)窗口,支持查找(替换)操作 。 格式操作: 字体,颜色,左对齐,右对齐,居中对齐,加粗,斜体,下划线 附加功能:插入图片

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WordEditor
{
    
    public partial class Form1 : Form
    {
        private String title = “Untitled“; //保存文件的标题
        Encoding encoding = Encoding.UTF32;

        public Form1()
        {
            InitializeComponent();
        }


        private void 打开OToolStripMenuItem_Click(object sender EventArgs e)
        {
            openFileDialog1.Filter = “文本文件|*.txt;*.html;*.docx;*.doc;*.rtf|所有文件|*.*“;//文件打开的过滤器;
            if(openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                title = openFileDialog1.FileName;
                this.Text = title; //显示打开的文件名
                richTextBox1.Modified = false;
                string ext = title.Substring(title.LastIndexOf(“.“) + 1); //获取文件格式;
                ext = ext.ToLower(); //转换成小写
                System.IO.FileStream fs = new System.IO.FileStream(title System.IO.FileMode.Open System.IO.FileAccess.Read);
                System.IO.StreamReader sr = new System.IO.StreamReader(fsEncoding.Default);//以UTF-8格式进行读取文件
                if(ext == “rtf“) //加载rtf文件
                {
                    richTextBox1.LoadFile(title RichTextBoxStreamType.RichText);
                }
                else
                {
                    richTextBox1.Text = sr.ReadToEnd();//读取文件流从当前位置到结尾的所有字符
                }
                fs.Close();
                sr.Close();
            }




        }

        public void 保存SToolStripMenuItem_Click(object sender EventArgs e)
        {
                //如果不是已有的文件,那么则转到另存为界面进行选择保存路径进行保存
            if (title == “Untitled“) 
               另存为AToolStripMenuItem_Click(sender e);
            else{
                string ext = title.Substring(title.LastIndexOf(“.“)+1);
                ext.ToLower();
                if (ext == “rtf“)
                    richTextBox1.SaveFile(title RichTextBoxStreamType.RichText);
                else if (ext == “doc“ || ext == “txt“)
                    richTextBox1.SaveFile(title RichTextBoxStreamType.PlainText);
                else if (ext == “uni“)
                    richTextBox1.SaveFile(title RichTextBoxStreamType.UnicodePlainText);
                else
                    richTextBox1.SaveFile(title RichTextBoxStreamType.PlainText);
                richTextBox1.Modified = false;
            }
        }

        //加粗
        private void boldToolStripMenuItem_Click(object sender EventArgs e)
        {
            richTextBox1.SelectionFont = new Font(richTextBox1.SelectionFont richTextBox1.SelectionFont.style ^ Fontstyle.Bold);
        }

        //斜体
        private void italicToolStripMenuItem_Click(object sender EventArgs e)
        {
            richTextBox1.SelectionFont = new Font(ric

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     43520  2018-12-23 01:42  WordEditor\.vs\WordEditor\v15\.suo

     文件          0  2018-12-20 16:04  WordEditor\.vs\WordEditor\v15\Server\sqlite3\db.lock

     文件     598016  2018-12-23 00:37  WordEditor\.vs\WordEditor\v15\Server\sqlite3\storage.ide

     文件      32768  2018-12-22 17:58  WordEditor\.vs\WordEditor\v15\Server\sqlite3\storage.ide-shm

     文件    4136512  2018-12-23 01:42  WordEditor\.vs\WordEditor\v15\Server\sqlite3\storage.ide-wal

     文件        189  2018-12-20 16:04  WordEditor\App.config

     文件      39424  2018-12-23 01:35  WordEditor\bin\Debug\WordEditor.exe

     文件        189  2018-12-20 16:04  WordEditor\bin\Debug\WordEditor.exe.config

     文件      56832  2018-12-23 01:35  WordEditor\bin\Debug\WordEditor.pdb

     文件      10754  2018-12-23 01:35  WordEditor\Form1.cs

     文件      30670  2018-12-23 00:38  WordEditor\Form1.Designer.cs

     文件      21294  2018-12-23 00:38  WordEditor\Form1.resx

     文件       3337  2018-12-23 01:32  WordEditor\form2.cs

     文件       8823  2018-12-22 15:49  WordEditor\form2.Designer.cs

     文件       5817  2018-12-22 15:49  WordEditor\form2.resx

     文件        753  2018-12-23 00:39  WordEditor\Form3.cs

     文件       3376  2018-12-23 00:39  WordEditor\Form3.Designer.cs

     文件       5817  2018-12-23 00:39  WordEditor\Form3.resx

     文件       1443  2018-12-22 13:28  WordEditor\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7108  2018-12-23 00:31  WordEditor\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件          0  2018-12-20 16:04  WordEditor\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2018-12-20 16:04  WordEditor\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

     文件          0  2018-12-20 16:04  WordEditor\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

     文件         42  2018-12-23 00:31  WordEditor\obj\Debug\WordEditor.csproj.CoreCompileInputs.cache

     文件        797  2018-12-23 00:38  WordEditor\obj\Debug\WordEditor.csproj.FileListAbsolute.txt

     文件       1128  2018-12-23 00:39  WordEditor\obj\Debug\WordEditor.csproj.GenerateResource.cache

     文件      11490  2018-12-22 13:47  WordEditor\obj\Debug\WordEditor.csprojAssemblyReference.cache

     文件      39424  2018-12-23 01:35  WordEditor\obj\Debug\WordEditor.exe

     文件      11133  2018-12-23 00:38  WordEditor\obj\Debug\WordEditor.Form1.resources

     文件        180  2018-12-23 00:38  WordEditor\obj\Debug\WordEditor.form2.resources

............此处省略27个文件信息

评论

共有 条评论

相关资源