C#中用RichTextBox实现图文混排和保存的例子

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.IO;

namespace test
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : Form
	{
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		
		void Button1Click(object sender, EventArgs e)
		{
			richTextBox1.Focus();
			richTextBox1.Select(0, richTextBox1.Rtf.Length);
		}
		
		void Button2Click(object sender, EventArgs e)
		{
			Clipboard.SetData(DataFormats.Rtf, richTextBox1.SelectedRtf);//
		}
		
		void Button4Click(object sender, EventArgs e)
		{
			Clipboard.SetData(DataFormats.Rtf, richTextBox1.SelectedRtf);//复制RTF数据到剪贴板

            richTextBox1.SelectedRtf="";//再把当前选取的RTF内容清除掉,当前就实现剪切功能了.
		}
		
		void Button3Click(object sender, EventArgs e)
		{
			richTextBox1.Focus();
			richTextBox1.Paste();//
		}
		
		void Button5Click(object sender, EventArgs e)
		{
			FileStream fs=new FileStream("F:\\ppp.rtf",FileMode.Create ,FileAccess.Write);
			richTextBox1.SaveFile(fs,RichTextBoxStreamType.RichText);
			fs.Close();
		}
	}
}

 C#中用RichTextBox实现图文混排和保存的例子_第1张图片

你可能感兴趣的:(C#中用RichTextBox实现图文混排和保存的例子)