devxlogo

Insert a picture into a RichTextBox control

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 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")

See also  Comparing different methods of testing your Infrastructure-as-Code
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist