Results 1 to 14 of 14

Thread: [RESOLVED] [2008] how to save ClipBoard while copying?

  1. #1

    Thread Starter
    Lively Member mahammad()'s Avatar
    Join Date
    Jun 2008
    Location
    Cairo , Egypt
    Posts
    71

    Resolved [RESOLVED] [2008] how to save ClipBoard while copying?

    HI All

    I am crating project and I want to copy an image to clipboard and then paste it in RTB

    I used this and it worked
    vb Code:
    1. Clipboard.Clear
    2. Clipboard.SetImage("C:/Example.bmp")
    3. document.paste
    but however the old contains of the ClipBoard will cleared , so how can I copy and paste this image without lose the clipboard contain

    there's two ways I found but I couldn't did them in code and don't know if they can work or not??

    1-save the clipboard contain in another object or variable and them after copy paste the image bring them back to the clipboard

    2-create a new clipboared
    vb Code:
    1. Dim MyClipBoard As Clipboard
    but don't know how to paste from this clipboard

    help me please and thanks in advance
    Last edited by mahammad(); Aug 28th, 2008 at 02:30 PM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: [2008] how to save ClipBoard while copying?

    try this. it gets the first image from the clipboard, copies + pastes the second image, then copies the first image back to the clipboard

    vb Code:
    1. Dim img As Image = Clipboard.GetImage
    2. Clipboard.Clear()
    3. Clipboard.SetImage("C:/Example.bmp")
    4. document.paste()
    5. Clipboard.SetImage(img)

  3. #3

    Thread Starter
    Lively Member mahammad()'s Avatar
    Join Date
    Jun 2008
    Location
    Cairo , Egypt
    Posts
    71

    Exclamation Re: [2008] how to save ClipBoard while copying?

    thanks .paul. for your answer but you forgot that you must save copied text too and also data and audio , right?

    and I have did A small mistake in the code
    I typed
    vb Code:
    1. Clipboard.Setimage("c:/Example.bmp")
    and I can't type the path as string in this method so I use this
    vb Code:
    1. Clipboard.Setimage(My.Resources.Examples)

    but I think that if I paste the image with another mothod not by Clipboard will be better , What do you see?

    thanks

  4. #4
    Addicted Member
    Join Date
    Aug 2007
    Location
    Miami, FL USA
    Posts
    171

    Re: [2008] how to save ClipBoard while copying?

    Why do you want to store data in the clipboard?

  5. #5
    Addicted Member
    Join Date
    Aug 2007
    Location
    Miami, FL USA
    Posts
    171

    Re: [2008] how to save ClipBoard while copying?

    And you could do

    vb Code:
    1. Clipboard.Setimage(Image.FromFile("c:/Example.bmp"))

  6. #6

    Thread Starter
    Lively Member mahammad()'s Avatar
    Join Date
    Jun 2008
    Location
    Cairo , Egypt
    Posts
    71

    Re: [2008] how to save ClipBoard while copying?

    Quote Originally Posted by NStuff42
    Why do you want to store data in the clipboard?
    do you mean the image that will copied or the old data in the clipboard?
    if the clipboard data just I don't want from users to lose their own data when they insert a picture to the file
    if the Image simply to paste it using 'RTB.paste()'
    and is there other way to insert picture to RTB ?

    thanks all

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: [2008] how to save ClipBoard while copying?

    try this. it should work with any clipboard dataformat

    vb Code:
    1. Dim data As Object = Clipboard.GetDataObject
    2. Clipboard.Clear()
    3. Clipboard.SetImage(Image.FromFile("c:\Example.bmp"))
    4. document.Paste()
    5. Clipboard.SetDataObject(data)
    Last edited by .paul.; Aug 28th, 2008 at 04:43 PM.

  8. #8
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: [2008] how to save ClipBoard while copying?

    Why do you want to copy an image to the clipboard and then paste it?

    What exactly are you doing? Since then you can just place it in a variable.

  9. #9

    Thread Starter
    Lively Member mahammad()'s Avatar
    Join Date
    Jun 2008
    Location
    Cairo , Egypt
    Posts
    71

    Exclamation Re: [2008] how to save ClipBoard while copying?

    Quote Originally Posted by .paul.
    try this. it should work with any clipboard dataformat

    vb Code:
    1. Dim data As Object = Clipboard.GetDataObject
    2. Clipboard.Clear()
    3. Clipboard.SetImage(Image.FromFile("c:\Example.bmp"))
    4. document.Paste()
    5. Clipboard.SetDataObject(data)
    OK I will try it thnx

  10. #10

    Thread Starter
    Lively Member mahammad()'s Avatar
    Join Date
    Jun 2008
    Location
    Cairo , Egypt
    Posts
    71

    Re: [2008] how to save ClipBoard while copying?

    Quote Originally Posted by noahssite
    Why do you want to copy an image to the clipboard and then paste it?

    What exactly are you doing? Since then you can just place it in a variable.
    I want to copy the image to the clipboard and paste it because it's the only method I know to insert image to RTB

    That's all I want to do just inserting image to richtextbox but is there otherway to do that please tell me

    thanks

  11. #11
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Re: [2008] how to save ClipBoard while copying?

    Quote Originally Posted by mahammad()
    I want to copy the image to the clipboard and paste it because it's the only method I know to insert image to RTB

    That's all I want to do just inserting image to richtextbox but is there otherway to do that please tell me

    thanks
    The article at the below link explains exactly what you need.

    http://www.codeproject.com/KB/edit/c...=2524851&fr=76

  12. #12

    Thread Starter
    Lively Member mahammad()'s Avatar
    Join Date
    Jun 2008
    Location
    Cairo , Egypt
    Posts
    71

    Re: [2008] how to save ClipBoard while copying?

    Deepak , I didn't find what I want can you show me by code?
    do you mean this part of the article?
    Inserting an Image
    When an image is pasted into a RichTextBox (or WordPad or Microsoft Word), the image is embedded in a Windows Metafile (WMF) and the metafile is placed in the document. The InsertImage method does the same thing, but without using the clipboard. According to the RTF Specification v1.6, it is possible to insert bitmaps, JPEGs, GIFs, PNGs, and Enhanced Metafiles directly into an RTF document without first embedding them in a Windows Metafile. However, while this works with Microsoft Word, if images are not embedded in a Windows Metafile, WordPad and RichTextBox simply ignore them.
    thnx

  13. #13

  14. #14

    Thread Starter
    Lively Member mahammad()'s Avatar
    Join Date
    Jun 2008
    Location
    Cairo , Egypt
    Posts
    71

    Re: [2008] how to save ClipBoard while copying?

    Deepak , I didn't found what can help me in this article
    but the code .paul. posted (POST#7) was very helpful
    the problem has resolved

    thanks all

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