標籤:style blog http io os ar 使用 for sp
1“.RTF”是什嗎?
多資訊文本格式 (RTF) 是一種方便於不同的裝置、系統查看的文本和圖形文檔格式。
RTF 使用美國國內標準協會 (ANSI)、 PC-8、 Macintosh(mac蘋果),或 IBM 的 PC 字元設定控制顯示形式和列印形式。
在不同的作業系統下建立的RTF文檔可以在多種作業系統和應用程式之間互相傳輸、查看。
當前,作為 MS-DOS、 Microsoft Windows、 OS/2、 Macintosh蘋果系統,應用程式之間處理文檔的特殊翻譯軟體。
RTF是Rich Text Format的縮寫,意即多文本格式。這是一種類似DOC格式(Word文檔)的檔案,有很好的相容性,使用Windows“附件”中的“寫字板”就能開啟並進行編輯。使用“寫字板”開啟一個RTF格式檔案時,將看到檔案的內容;如果要查看RTF格式檔案的原始碼,只要使用“記事本”將它開啟就行了。這就是說,你完全可以像編輯HTML檔案一樣,使用“記事本”來編輯RTF格式檔案。
作為微軟公司的標準檔案,早期外界需要數十美元向微軟付款,才能購買一本薄薄的RTF標準檔案。不過隨著採用RTF格式標準的軟體愈來愈多,RTF格式也愈來愈普遍,微軟公司就把標準檔案公開,放在網上供開發人員下載。
RTF格式是許多軟體都能夠識別的檔案格式。比如Word、WPS Office、Excel等都可以開啟RTF格式的檔案。
對普通使用者而言,RTF格式是一個很好的檔案格式轉換工具,用於在不同應用程式之間進行格式化文字文件的傳送。
通用相容性應該是RTF的最大優點,但同時也就具有它的缺點,比如檔案一般相對較大(可能因為嵌入了相容各種應用程式的控制符號吧)、WORD等應用軟體特有的格式可能無法正常儲存等。
2.代碼如下:
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() { InitializeComponent(); } /// <summary> /// 擷取文檔編輯地區使用的 RtfEditor 執行個體。 /// </summary> internal RtfEditor RtfEditor { get { return rtfEditor; } } void rtfEditor_FileNameChanged(object sender, EventArgs e) { string FileName = Path.GetFileName(rtfEditor.FileFullName); if (FileName == "") FileName = "YYS-RTF編輯器"; 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> /// 在關閉程式之前,判斷文本是否需要儲存 /// </summary> private void App_Closing(FormClosingEventArgs e) { if (rtfEditor.Modified) {//文檔被修改過 DialogResult result = MessageBox.Show("檔案內容已更改,想儲存檔案嗎?", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information); switch (result) { case DialogResult.Yes: //“儲存”,則執行儲存檔案的操作 //如果沒有選擇要儲存的檔案名稱,則彈出儲存對話方塊,由使用者選擇要儲存的檔案名稱後儲存文本 if (saveFileDialog.FileName == "") { if (saveFileDialog.ShowDialog(this.TopLevelControl) == DialogResult.OK) { rtfEditor.SaveFile(saveFileDialog.FileName, RichTextBoxStreamType.PlainText); } } else { //如果已經選擇了要儲存的檔案名稱,則儲存文本到檔案中 rtfEditor.SaveFile(saveFileDialog.FileName, RichTextBoxStreamType.PlainText); } break; case DialogResult.No://不儲存 break; default://取消操作 e.Cancel = true; break; } } } /// <summary> /// 事件處理 - 視窗關閉 /// </summary> /// <param name="e"></param> protected override void OnFormClosing(FormClosingEventArgs e) { base.OnFormClosing(e); if (!this.Modal) App_Closing(e); } }}
3.:
c#-RTF文字編輯器