I need to be able to insert a picture into a RichText Box. Is it possible?
Printable View
I need to be able to insert a picture into a RichText Box. Is it possible?
Yes.... give me a sec.
Try this:
Umm... doesn't work.
I added the components Richtext Box and Windows Common Controls and I get my first error on
Form_Load
RTB.TextRTf
What's the error?
Let's try with the whole project...
lol
Sorry I forgot the most important part.
Method or Data Member Not Found
I'm guessing you haven't done whatever it is that you have to do to make the Picture box think its a Rich TextBox
What controls are meant to be on the form??
Cause you didn't inlucde the Project file so....
Download the last ZIP... I included the project file as well
Aah works perfectly!!!
Thanks a million :)
You're welcome.
Ohh.... I'm using the following code to send a picture to it
VB Code:
Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then RTB.Text = RTB.Text + "<(BugFix)>" PasteImages End If End Sub
But it takes the Image which is already there any moves it to the new postion. Is it possible to have multiple images?
Yes... but you should "load" all the "<(BugFix)>" first, and the call the PasteImages.
You might add images interactually with a similar code if you want.
Try this:VB Code:
Option Explicit 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 Form_Load() RTB.TextRTF = "This image <(BugFix)> is a BugFix" PasteImages End Sub Private Function ParseFirst(Text As String, lStart As Long, lStop As Long) As String ParseFirst = "" lStart = InStr(Text, "<(") If lStart Then lStop = InStr(lStart, Text, ")>") ParseFirst = Mid$(Text, lStart + 2, lStop - lStart - 2) End If End Function Private Sub PasteImages() Dim i As Integer Dim e0 As String Dim lStart As Long, lStop As Long RTB.Tag = RTB.Text Do e0 = ParseFirst(RTB.Text, lStart, lStop) If e0 = "" Then Exit Do 'clear clipboard of any data Clipboard.Clear 'save pic to clipboard Clipboard.SetData ImgLst.ListImages(e0).Picture, vbCFBitmap Do Until RTB.Find("<(" & e0 & ")>") = -1 RTB.Locked = False RTB.SelStart = RTB.Find("<(" & e0 & ")>") RTB.SelLength = Len("<(" & e0 & ")>") SendMessage RTB.hwnd, WM_PASTE, 0, 0 RTB.Locked = True Loop Loop End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then RTB.TextRTF = RTB.Tag + "<(BugFix)>" PasteImages End If End Sub
Ok.... have u tried it with heaps of pictures.... it gets abit weird.
I removes the icons from the screen and then redoes them... so you can see the <(BugFix)> Text. Scrolling works fine... but everytime the user enters some thing
An example might be holding Enter in the above example.
I'm guessing its not possible to fix this.
My computer is too fast to see that, anyway!!
Oh ok :D
I'm running a Cel 1.1.
Its because your clearing the text and reinserting the pictures
The problem is is that I have to run this on a P110
Hopefully it'll be usable.
I've replaced the Bitmap with a Gif and I get an error on,
VB Code:
Clipboard.SetData ImgLst.ListImages(e0).Picture, vbCFBitmap
What do I need to change it 2? I had a look under help and it didn't show me anything to useful.
Should I just convert the Gifs to Bitmaps?
Come on Guys, nearly done!! :D
Ok... I tried to put this in my Chat Program, and I got an error when I try to insert a Gif or Bmp instead the image that you included in the Image List.
Urgh what do I need to change??? :mad:
Heres the my Project is you guys are feeling really helpful.
http://www.vbforums.com/showthread.p...hreadid=188577
Ok, I've gotten rid of the Image List, so now I'm just using a Picture Box.
Now the Problem is that its possible to resize the picture
Is it possible to change this?
Are you talking about the Autosize property?
No...
When the image is pasted into the RichtextBox, the user can resize it, which is not good.
Also, how can be able handle more than one picture? (like what do I need to change in the parser?
Thanks in Advance.
Bump
ok i had the same problem with "resizability". The only way i was able to get around this was to prevent people from highlighting the text. Whenever they would onmousedown or onmouseup, i would set the selection length to zero. This prevents resizing.
Yeah... good idea.
But how can I allow for more than one picture?? Just create multiple parsers?? :confused:
Thanks in Advance.
i had them in the onmousedown and onmouseup properties of the richtextbox. However, it prevente highlighting ANY text.
For what I want to use it for, locking it is fine.... can't believe that I didn't think of that early. :D
But now all I need is the above code being able to handle mutliple pictures.
Its easier to replace the imagelist with picture boxs I found.... if anyone cares. :D
Yet another *--------BuMp--------*
Noone...?? Surely it can't be that hard.....
I guess, you can paste it anywhere... the secret are in these lines:VB Code:
RTB.SelStart = RTB.Find("<(" & e0 & ")>") RTB.SelLength = Len("<(" & e0 & ")>") SendMessage RTB.hwnd, WM_PASTE, 0, 0
You have to select the place where you want to place your image, and paste it
I reallize that this thread is very old but i was wondering if somthign can be changed with this solution? This code processes all the richtextbox text and then researches it to replace the given strings with an image by paisting. What i was wondering is if you can make this process only the text between the last 2 vbCrLf and still keep the original text and images before these 2 vbCrLf
Any ideas?