Here’s a simple method to programmatically insert an image into a RichTextBox control, by copying it into the clipboard and then pasting it into the control:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal _ hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _ lParam As Any) As LongPrivate Const WM_PASTE = &H302Sub InsertPictureInRichTextBox(RTB As RichTextBox, Picture As StdPicture) ' copy into the clipboard ' Copy the picture into the clipboard. Clipboard.Clear Clipboard.SetData Picture ' paste into the RichTextBox control SendMessage RTB.hwnd, WM_PASTE, 0, 0End Sub
You can load the picture from another control (a PictureBox, for example), or directly from a file using the LoadPicture function:
InsertPictureInRichTextBox RichTextBox1, LoadPicture("c:winntcoffee bean.bmp")