I have been working on a Windows application that used a RichTextBox control to display read-only data. After a few version of the application I decided that I'd like the control to also display images. I was always under the impression that with a RichTextBox control such a task would be quite easy and come straight out of the box. I was quite mistaken when I went through the first 10 guides and "how to"s online. Eventually I came across the Inserting images into a RichTextBox control (the OLE way) at CodeProject which lead me to a nice, clean and fast solution.

 The usage is quite simple and straight forward, the following snippet loads a Bitmap from a stream, sends the current selection of the RichTextBox control to be the 10th character and inserts an image at that location. 

using (Bitmap image = (Bitmap)Bitmap.FromStream(...))

{

    this.richTextBox.SelectionStart = 10;

    this.richTextBox.SelectionLength = 0;

 

    this.richTextBox.InsertImage(image, match.Index);

}

Download RichTextBoxEx.zip