c#中读写rtf文件

来源:互联网 发布:mac怎么去资源库 编辑:程序博客网 时间:2024/05/17 03:06
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 在RichTextBox中显示RTF文件{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();            this.btnSave.Click+=new EventHandler(btnSave_Click);            this.btnOPen.Click+=new EventHandler(btnOPen_Click);            this.btnClear.Click+=new EventHandler(btnClear_Click);            this.btnClose.Click+=new EventHandler(btnClose_Click);        }        private void btnSave_Click(object sender, EventArgs e)        {            SaveFileDialog sfd = new SaveFileDialog();            sfd.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory;            sfd.Filter = "RTF文件|*.rtf";            if (sfd.ShowDialog() == DialogResult.OK && sfd.FileName!="")            {                richTextBox1.SaveFile(sfd.FileName);            }            MessageBox.Show("保存成功");        }        private void btnOPen_Click(object sender, EventArgs e)         {            OpenFileDialog ofd = new OpenFileDialog();            ofd.Filter = "RTF文件|*.rtf;*.doc|所有文件|*.*";            ofd.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory;            if (ofd.ShowDialog() == DialogResult.OK && ofd.FileNames.Length>0)            {                string fi = ofd.FileName;                richTextBox1.LoadFile(fi);            }        }        private void btnClear_Click(object sender, EventArgs e)        {            richTextBox1.Text = "";        }        private void btnClose_Click(object sender, EventArgs e)        {            Application.Exit();        }    }}

原创粉丝点击