以下是关于扩展插入图片的代码:由于其他功能和本身提供的一样故在这里就不再贴代码了,只是把其中的关于插入图片的封装贴出来。
#region Insert Image
/// <summary>
/// Inserts an image into the RichTextBox. The image is wrapped in a Windows
/// Format Metafile, because although Microsoft discourages the use of a WMF,
/// the RichTextBox (and even MS Word), wraps an image in a WMF before inserting
/// the image into a document. The WMF is attached in HEX format (a string of
/// HEX numbers).
///
/// The RTF Specification v1.6 says that you should be able to insert bitmaps,
/// .jpegs, .gifs, .pngs, and Enhanced Metafiles (.emf) directly into an RTF
/// document without the WMF wrapper. This works fine with MS Word,
/// however, when you don't wrap images in a WMF, WordPad and
/// RichTextBoxes simply ignore them. Both use the riched20.dll or msfted.dll.
/// </summary>
/// <remarks>
/// NOTE: The image is inserted wherever the caret is at the time of the call,
/// and if any text is selected, that text is replaced.
/// </remarks>
/// <param name="_image"></param>
public void InsertImage(Image _image)
{
StringBuilder _rtf = new StringBuilder();
// Append the RTF header
_rtf.Append(RTF_HEADER);
// Create the font table using the RichTextBox's current font and append
// it to the RTF string
_rtf.Append(GetFontTable(this.Font));
// Create the image control string and append it to the RTF string
_rtf.Append(GetImagePrefix(_image));
// Create the Windows Metafile and append its bytes in HEX format
_rtf.Append(GetRtfImage(_image));
// Close the RTF image control string
_rtf.Append(RTF_IMAGE_POST);
this.SelectedRtf = _rtf.ToString();
}
/// <summary>
/// Creates the RTF control string that describes the image being inserted.
/// This des cription (in this case) specifies that the image is an