Results 1 to 10 of 10

Thread: How do you put an image inside a richtextbox?

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    34

    How do you put an image inside a richtextbox?

    Is it possible to add an image inside a richtextbox so that it is visible within the interface and also printable?

    Where would I start?

    What I am looking to do is fill in text boxes and combo boxes on one side of my form while a richtextbox displays the information on the rightside of my form. Bascially the user is entering in data and a "print preview" invoice is being generated on the right side. The image I want to place in the RTB is my company's logo. Of course this image must print with the rest of the invoice.

    Thanks!
    - Dan

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: How do you put an image inside a richtextbox?

    this is how i did it.. there might be a better way

    put your logo in an image control... hide it if u want..

    VB Code:
    1. 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
    2. Private Const WM_PASTE = &H302
    3.  
    4.  
    5.  
    6. Private Sub Command1_Click()
    7.     Clipboard.Clear
    8.     Clipboard.SetData Image1.Image
    9.     SendMessage RTB1.hWnd, WM_PASTE, 0, 0
    10. End Sub
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: How do you put an image inside a richtextbox?

    There are atleast 3 methods. But this one may be the easiest.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: How do you put an image inside a richtextbox?

    I win
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: How do you put an image inside a richtextbox?

    Quote Originally Posted by Static
    I win
    Well done !






    Have a lollypop.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    34

    Re: How do you put an image inside a richtextbox?

    Thanks guys for your help. I appreciate it very much! I want the logo to be present on formload...That is why I call it in the formload event, obviously...lol Other than that I think I'm pretty much following your examples...Aren't I?

    This code works as far as inserting the image into the RTB, however, when I print the RTB, the image is not printed. Help is appreciated...

    Another thing, I'd like to be able to LOCK the RTB so the data can not be altered, other than with the Textboxes and combo boxes, however, when I lock it, the image doesn't show...Odd...

    VB Code:
    1. 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
    2. Private Const WM_PASTE = &H302
    3.  
    4. Private Sub PlaceLogo()
    5.     Clipboard.Clear
    6.     Clipboard.SetData Image1.Picture
    7.     SendMessage RTBLog.hWnd, WM_PASTE, 0, 0
    8. End Sub
    9.  
    10.  
    11. Private Sub Form_Load()
    12.     Call PlaceLogo
    13. End Sub
    14.  
    15.  
    16. Private Sub CmdPrintRecord_Click()
    17.     Printer.Print frmmain.rTxtLog.Text
    18.     Printer.EndDoc
    19. End Sub

  7. #7
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: How do you put an image inside a richtextbox?

    well. Lock it.. but
    Do this

    RTB1.Locked = False
    'add image
    RTB1.Locked = True


    not sure about printing though.....
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  8. #8

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    34

    Re: How do you put an image inside a richtextbox?

    Geeeze! Now why didn't I think of that? Thatnks Static!!

    Every find yourself overlooking the obvious for something less obvious? Seems to be the case here...There it is, staring me in the face...You're right, Lock it!

    Thanks again...

    Now, onto this printing issue...I gotta print that image...Anyone? Ideas?

    - Dan

  9. #9
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: How do you put an image inside a richtextbox?

    I haven't played with printing images from rtb, but one thought is that you can load the rtf into word and print from there.

    You can use the Word Object from VB to do this.

  10. #10
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: How do you put an image inside a richtextbox?

    Printing:
    There is a SelPrint method. It can print RTB contents with images.
    But it is not very good. Seach MSDN, there is a code to print RTB contents.

    Form_Load:
    If the image is always same, you can save it in a rtf file. Then you can add it in the rtb during design time, or you can use the LoadFile method at Form_Load.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width