C#-rtf Text Editor

Source: Internet
Author: User

1 ". RTF "What?"

Rich Text Format (RTF) is a text and graphics document format that is convenient for different devices and systems to view.


RTF uses the American National Standards Association (ANSI), PC-8, Macintosh (Mac Apple), or IBM's PC character settings to control the display form and print form.
RTF documents created under different operating systems can be transferred and viewed across multiple operating systems and applications.
Currently, as MS-DOS, Microsoft Windows, OS/2, Macintosh Apple systems, special translation software handles documents between applications.


RTF is the abbreviation for rich Text format, which means multiple text formats.

This is a file that is similar to DOC format (Word document) and has very good compatibility and can be opened and edited using WordPad in Windows accessories.

When you use WordPad to open a rich Text format file. You will see the contents of the file, and if you want to view the source of the RTF file, simply open it with Notepad. This means that you can use Notepad to edit Rich text format files just as you would edit HTML files.


As a standard document for Microsoft, the early outside world needs $ dozens of to pay Microsoft to buy a thin RTF standard file. Just as there are more and more software using RTF format standards. The RTF format is also becoming more common. Microsoft is exposing the standard documents. Put on the Internet for developers to download.
The RTF format is a file format that many software can recognize.

For example, Word, WPS Office, Excel, and so on can open RTF-formatted files.

For ordinary users, the RTF format is a very good file format conversion tool for formatting text-to-document transfers between different applications.
Universal compatibility should be the greatest advantage of RTF, but it also has its drawbacks at the same time. For example, files are generally relatively large (possibly due to embedded control symbols compatible with various applications), Word and other application software-specific formats may not be saved properly.

2. Code such as the following:

Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.text;using system.windows.forms;using system.io;using FCG. Windows.forms;namespace rtf{public partial class Rtf:form {public RTF () {initializecom        Ponent ();        }///<summary>//Get the Rtfeditor instance used in the document editing area. </summary> internal Rtfeditor Rtfeditor {get {return Rtfedi            Tor }} void Rtfeditor_filenamechanged (object sender, EventArgs e) {string FileName = path.ge            Tfilename (Rtfeditor.filefullname);            if (filename = = "") FileName = "Yys-rtf editor"; This.        Text = FileName; } protected override void OnLoad (EventArgs e) {base.                        OnLoad (e);            String[] args =environment.getcommandlineargs (); if (args. Length < 2)//aRg[0]=exepath, arg[1] = filename {//file_func_newfile ();                } else {string filename =args[1]; if (filename. Trim ().            ToLower ()! = "-test") rtfeditor.loadfile (filename);            } rtfeditor.filenamechanged + = new EventHandler (rtfeditor_filenamechanged);        Rtfeditor_filenamechanged (this, null); }///<summary>///Before closing the program, infer if the text needs to be saved///</summary> private void app_closing (for  Mclosingeventargs e) {if (rtfeditor.modified) {//document modified DialogResult result = MessageBox.Show ("The file contents have changed, do you want to save the file?"                "," hint ", Messageboxbuttons.yesnocancel, MessageBoxIcon.Information); Switch (Result) {case Dialogresult.yes://"Save", then run the Save file operation//assuming No Select the name of the file you want to save. The Save dialog box pops up. Save the text if the user chooses the name of the file to save (Savefiledialog.filename == "") {if (Savefiledialog.showdialog (this). Toplevelcontrol) = = DialogResult.OK) {rtfeditor.savefile (Savefi                            Ledialog.filename, Richtextboxstreamtype.plaintext); }} else {//assuming you have selected a file to save                        Name, then save the text into the file Rtfeditor.savefile (Savefiledialog.filename, Richtextboxstreamtype.plaintext);                    } break;                    Case dialogresult.no://does not save the break;                        default://Cancel Operation E.cancel = true;                Break  }}}///<summary> event handling-form closed///</summary>//<param Name= "E" ></param> protected override void Onformclosing (FormClosingEventArgs e) {base.            Onformclosing (e); if (!this.        Modal) app_closing (e); }    }}

3. What you see:


Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.

C#-rtf Text Editor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.