InsertImage() public method

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.
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.
public InsertImage ( Image _image ) : void
_image Image
return void
Example #1
0
		private void ics_ConferenceMessageReceived(object sender, string messageReceived, string fromUser)
		{
			Invoke(new MethodInvoker(delegate
			{
				var _rtBox = new ExRichTextBox();
				int _index;


				_rtBox.AppendTextAsRtf(fromUser + " Says\n",
									   new Font(this.Font, FontStyle.Bold), RtfColor.Blue);
				_rtBox.AppendTextAsRtf(messageReceived, new Font(this.Font, FontStyle.Bold), RtfColor.Gray);
				if ((_index = _rtBox.Find(":)")) > -1)
				{
					_rtBox.Select(_index, ":)".Length);
					_rtBox.InsertImage(pbSmile.Image);
				}
				chatForm.rtBox.AppendRtf(_rtBox.Rtf);
				// Scroll to bottom so newly added text is seen.
				chatForm.rtBox.Select(chatForm.rtBox.TextLength, 0);
				chatForm.rtBox.ScrollToCaret();

				// Return focus to message text box
				chatForm.txtSendMessage.Focus();
			}
			));
			
		}