Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: VB5,VB6
Expertise: Intermediate
Dec 20, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Insert a picture into a RichTextBox control

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 Long
Private Const WM_PASTE = &H302

Sub InsertPictureInRichTextBox(RTB As RichTextBox, Picture As StdPicture)
    ' copy into the clipboard
    ' Copy the picture into the clipboard.
    Clipboard.SetData Picture
    ' paste into the RichTextBox control
    SendMessage RTB.hwnd, WM_PASTE, 0, 0
End 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:\winnt\coffee bean.bmp")
Francesco Balena
Thanks for your registration, follow us on our social networks to keep up-to-date