7 Replies - 10088 Views - Last Post: 24 January 2011 - 12:59 PM Rate Topic: -----

#1 jimdandy75  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 311
  • Joined: 30-June 08

Paste image into RichTextBox

Posted 24 January 2011 - 10:16 AM

Is it possible to paste an image in VB's richtextbox like we can do with Word or Wordpad? I have tried all the tutorials I can find online and am still having no success getting an image from the clipboard to the RTB. I can accomplish it if I already know the image and path etc. and do it through code, but that will not allow someone to simply click an image, copy, and paste it into the rtb. Any help would be appreciated, thanks :smile2:

This post has been edited by jimdandy75: 24 January 2011 - 10:16 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Paste image into RichTextBox

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9427
  • View blog
  • Posts: 35,423
  • Joined: 12-June 08

Re: Paste image into RichTextBox

Posted 24 January 2011 - 10:32 AM

This seems pretty straight forward.


        Dim ClipImage As System.Drawing.Image = Nothing
        If My.Computer.Clipboard.ContainsImage() Then
            ClipImage = My.Computer.Clipboard.GetImage
        End If

        If ClipImage IsNot Nothing Then
            '-- paste into rich text box
            RichTextBox1.Paste()
        End If



Richtextbox1 is the control I dropped on the form.
I dumped this in my form's load method for quick testing.
I went to google's front page, right clicked on their logo, hit 'copy image', and then ran the program for testing.

It showed up fine.

This post has been edited by modi123_1: 24 January 2011 - 10:34 AM

Was This Post Helpful? 2
  • +
  • -

#3 jimdandy75  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 311
  • Joined: 30-June 08

Re: Paste image into RichTextBox

Posted 24 January 2011 - 11:09 AM

Thanks, that works for copying and pasting off the internet when it gives you the 'copy image' option. But how can I get it to work when I copy and paste a local image off my hdd?
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9427
  • View blog
  • Posts: 35,423
  • Joined: 12-June 08

Re: Paste image into RichTextBox

Posted 24 January 2011 - 11:22 AM

You mean right click on a file in a folder, click 'copy', and then paste?
Was This Post Helpful? 0
  • +
  • -

#5 jimdandy75  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 311
  • Joined: 30-June 08

Re: Paste image into RichTextBox

Posted 24 January 2011 - 11:24 AM

Yeah, it works on Word and WordPad. Doesn't seem possible on the VB RTB though? >_<
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9427
  • View blog
  • Posts: 35,423
  • Joined: 12-June 08

Re: Paste image into RichTextBox

Posted 24 January 2011 - 11:42 AM

Oh it's possible. You haven't looked much into that 'my.computer.clipboard' have you?

Look at "my.Computer.Clipboard.GetFileDropList".
http://msdn.microsof...v=VS.80%29.aspx
http://msdn.microsof...v=VS.80%29.aspx

You can get the image's location string from the clipboard (the whole image isn't on as if you were copying it from a browser). From there badabing, bada boom.
Was This Post Helpful? 1
  • +
  • -

#7 jimdandy75  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 311
  • Joined: 30-June 08

Re: Paste image into RichTextBox

Posted 24 January 2011 - 12:55 PM

You, my friend, are frickin awesome!!!! Thank you so much! :bananaman:
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9427
  • View blog
  • Posts: 35,423
  • Joined: 12-June 08

Re: Paste image into RichTextBox

Posted 24 January 2011 - 12:59 PM

Not a problem.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1