I want to drag an image into, say, Safari (or Firefox, but I do not checked it, yet) and was
I do not know from where to start. A simple search in the documentation leads me to:
Dim d As DragItem
d = New DragItem(Self, X, Y, Me.Width, Me.Height)
d.Picture = Me.Backdrop
d.Drag //Allow the drag
In source Vanvas MouseDown.
It works nice as another Canvas in the same window (and I do not need that), but not into Safari.
Then I recall the examples, and one: DragPictureExample.
Very nice, but it does not do the trick. The Studebaker is nice, but is not displayed on the Safari window.
Idea on how I can achieve that ?
Edit: I especially love this line
d.DragPicture = Me.Backdrop // Display the image to be dropped
I think you must use a temporary folderitem, the browser expects a URL
I am able to drop an image file (png) into the web browser (but that may not contradict your statement) on Firefox.
On Safari, I have to rop the image into the URL field: you really are right Axel.
Another trick to test
Well, there is a difference between dragging a Picture itself (in memory), a file path to a picture on disk or an URL to a picture.
Which do you want?
simply drop an image onto the brower tab (Safari / Firefox
).
I probably have to fill DragItem.FolderItem
.
The answer was:
d.FolderItem = TmpFI
Where TmpFI
is a Reference to the drag image saved in the SpecialFolder.Temporary.
Thank you Axel.
And to get the image appears below the Mouse cursor (instead of far left):
d = New DragItem(Self, Me.Left, Me.Top, Me.Width, Me.Height)
Me
refers to the owning Canvas
from where you do the Drag
.
This is the first time in 20 years that I am able to achieve that: drop an image from a Xojo Canvas into the Finder. I have to check what happens when running in Windows
Runs fine on WIndows XP !!!
While I am at it, here is the whole MoiuseDown Event:
[code]Function MouseDown(X As Integer, Y As Integer) As Boolean
// Drag outside this application (to a web browser ?)
Dim ExportDI As DragItem
Dim TmpFI As FolderItem
Dim SQLDate As New Date
Dim SuffixName As String
// To make the file name unique
SuffixName = ReplaceAll(SQLDate.SQLDateTime,":","-")
// Save the image into Temporary
TmpFI = SpecialFolder.Temporary.Child("Windows 10 Icon - " + SuffixName + “.png”)
// Save the image in the Temporary Folder (Directory)
Me.Backdrop.Save(TmpFI,Picture.SaveAsPNG)
// Do the Drag
ExportDI = New DragItem(Self, Me.Left, Me.Top, Me.Width, Me.Height)
ExportDI.Picture = Me.Backdrop
ExportDI.DragPicture = Me.Backdrop
ExportDI.FolderItem = TmpFI
ExportDI.Drag // Allow the drag
End Function[/code]
Edit: added SQLDateTime
to set the file name unique.