I am using CHartDirector, and I have the following code.
Dim c as new Clipboard
The picture is on the clipboard in Windows, but if the user selects paste, any text on the clipboard is pasted. The user must select past special, then paste as device independent bitmap to get the picture. Is there a way to put the picture on the clipboard so that it is the default item pasted?
It pastes straight away in paint. In Microsoft Word or PowerPoint I have to select “Paste Special”, “Device Independent Bitmap” or “Bitmap” to make it work. Without paste special, it tries to paste text.
The clipboard can carry several things. I would follow Jeff’s suggestion and set Clipboard.text to nil or “”.
Dim c as new Clipboard
c.Text = ""
My guess is that if the Clipboard has both text and picture info, pasting it to Paint (for example) will past the picture info (because that is what it expects); but pasting it to Word or Powerpoint (that accept text as well as pictures - and many other things) will require to be very specific about what you want to paste (i.e. using PasteSpecial) or modifying the DefaultPaste option.
I’ve just tried this, and it does NOT work. I am running a 2017r1 64-bit Windows application, and cannot get it to paste into MS Excel, even after setting the clipboard text to and empty string. In the pat, I had used the MonkeybreadWindowsClipboardMBS object to get around this, but that also stopped working as of 2017r1.
Yes, I have had the same problem and there is something that is not working when copy-and-pasting pictures into Excel from Xojo.
I have a simple workaround from my Excel 2016 Book, and it saves a picture from Xojo and then commands are used to load the picture from Excel. Its not copy-and-paste, its more like save-and-load. Here is the code from the book:
[code]Dim excel as new ExcelApplication
excel.visible = true
Dim TheSaveFolder as String
Dim f as FolderItem
Dim aPict as new Picture(400, 300, 32)
f = SpecialFolder.Pictures.Child(“Temp_Image.bmp”)
TheSaveFolder = f.AbsolutePath
MsgBox “Excel will now quit”
excel = nil
Exception err as OLEException
There is a (https://xojo.com/issue/48686)>]Feedback 48686 from @Bryan Dodson and the status is FIXED AND VERIFIIED.
I did some testing on Win10, xojo 2017R2b14 and it still did not work as expected. Downloaded the sample + graphics Bryan included in his FB and even this did not work.
I looks like the xojo picture object is not accepted by the Windows clipboard, since the xojo clipboard object contains the data, according to the debugger.
As a work around I was thinking about saving the picture to a file and find a way to get the file copied into the clipboard.
Saving is no problem, getting the file into clipboard by code is. Getting the binary stream is not the issue but put it in the clipboard in a way it’s recognized as a pic ?
Thanks, @Eugene Dakin. Unfortunately, the users of our application may be pasting into any one of several target apps, not all of which can be addressed by Office Automation.
@Joost Rongen - This has been a long-standing problem which we worked around for years by using @Christian Schmitz 's WindowsClipboardMBS object. For whatever reason, this stopped working as of 2017r1 or 1.1. I think Christian believes it may have to do with a change in Xojo drawing on Windows.
“Paste Special” does work, though our users are not happy to have to take this extra step as the result of an “improvement” to our application. When we use the Xojo clipboard object, Excel always pastes the text, even if it’s an empty string. Now, when we use the MBS object, Excel reports that it is unable to paste the picture data. So, there is apparently something in the Windows clipboard which tells the target to prefer the picture over the text, but the picture data put on the clipboard by the MBS code is currently somehow wrong.
I’ll sign on to the feedback case you linked to, Joost.
yes … eh … NO ! it’s still NOT WORKING. I really don’t understand why and how (https://xojo.com/issue/48686)>]FB 48686 has been closed as being fixed. Just not tested in the context of the problem. And why do you have to raise a new feedback ? Just say sorry and reopen this one, it’s clear enough and reproducing this issue is just 4 short lines of code and Windows up and running. (Guess the last one was not tested)
Have you started a new one Peter ? What number ?
There is a big chance that the solution to the problem is much more difficult than the problem looks like. According to me, the Windows clipboard doesn’t take the content of a xojo picture object as a picture.
Hopefully the team will give extra attention to this one for the next release.
@Joost Rongen - I agree, but was sick today, so have nit created a new case. Feel free if you want to; otherwise, I can tomorrow, I hope.
Interestingly, it did work for me ONCE when I first tested, but I couldn’t get it to do it again. It does work when pasting into some target apps that don’t handle text (like Paint), but not Excel or Word. I think that these apps prefer text on the clipboard, even if it’s an empty string. But, past behavior of WindowsClipbardMBS suggests that there is some way to get these target apps to ignore the text.
Is there a way to actually set the clipboard’s text to NIL rather than an empty string?
The problem with that is that as far as I can tell, there is no way to do it.
Unlike WindowsClipboardMBS, the Xojo Clipboard object has no “clear()” method. It appears that even setting the Clipboard.text property to an empty string is seen as a valid string by various target applications, and they prefer the text over the picture.
If you could look into why your class stopped working, it would be much appreciated.