How can I insert an image in a richtextbox?
Thanx in advance.
Printable View
How can I insert an image in a richtextbox?
Thanx in advance.
use the search feature on the boards, this question has been posted hundreds of times
Try this :
VB Code:
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 Private Sub Command1_Click() Clipboard.SetData Picture1.Picture, vbCFBitmap DoEvents SendMessage RichTextBox1.hwnd, WM_PASTE, 0, 0 End Sub
yeah, but that also clears any images the user might have on the clipboard.
That just a suggestion
i know... another possibility is to put the contents of the clipboard's data property into a picbox, running that code, and then copying the old data back into the clipboard.
Thye might have a way to do it without the clipboard.
i know there is, but obviously he couldn't think to search the boards first so u gave him a good answer that he can use
Yes :D
Without the clipboard....
VB Code:
rtb.OLEObjects.Add , , "C:\Windows\bubbles.bmp"
Yes it work well thx YoungBuck
it not working with JPEG
because VB is a flaming homosexual, and it only likes Bitmaps, you have to first find code to conver the JPG into a BMP, and then load the BMP
ahahahahaha:D :)
Thanx DaoK & YoungBuck appreciate the help but {rtb.OLEObjects.Add , , "C:\Windows\bubbles.bmp"} opens the default program for that image. Do you know to fix this.
Btw, I searched on the board for it I couldn't find the solution to this problem. And don't go flaming me, I'm only a kid.
rtb.OLEObjects.Add , , "C:\Windows\bubbles.bmp"
Did not open paint. but when i try something like
rtb.OLEObjects.Add , , "C:\Windows\bubbles.JPG"
I have an icon and my paint program open... maybe the file you try to open is not BMP.
It is a bitmap. Second, i can't load images from a resource file.
Best regards
Quote:
Originally posted by Patoooey
Been a while since I've had to put an image into an RTB. Used this back them. Might be a better way now-a-days but this does work. :)
VB Code:
' character pos to insert at RichTextBox1.SelStart = 235 ' load pix Picture1.Picture = LoadPicture("d:\myimage.gif") DoEvents ' save as BMP SavePicture Picture1.Picture, "d:\c663dn5a.bmp" DoEvents ' Load BMP RichTextBox1.OLEObjects.Add , , "d:\c663dn5a.bmp" DoEvents
Kings your code work but you can do it in reverse ( BMp to jpeg/gif).