Platforms to show: All Mac Windows Linux Cross-Platform

/Win/Drag and Drop/Picture Drag


Required plugins for this example: MBS Main Plugin, MBS Win Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Win/Drag and Drop/Picture Drag

This example is the version from Sun, 17th Mar 2012.

Project "Picture Drag.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
Class PictureDragWindow Inherits Window
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
EventHandler Sub Open() dim logo as Picture = logoMBS(100) me.Backdrop = logo End EventHandler
End Control
EventHandler Function MouseDown(X As Integer, Y As Integer) As Boolean DragStarted = false Return true End EventHandler
EventHandler Sub MouseDrag(X As Integer, Y As Integer) if DragStarted then Return DragStarted = true // avoid a new drag if the user pressed Escape key and is still dragging dropsource = new PictureDragSource dim logo as Picture = logoMBS(100) dim data as new WinDataObjectMBS(logo) data.AddDragImage(logo, logo.Width, logo.Height, 0, 0) dim effect as integer = 0 dim result as integer = dropsource.DoDragDrop(data, dropsource.DROPEFFECT_COPY, effect) // finished. Check the return values to see if we need to do anything else if Result = dropsource.DRAGDROP_S_DROP then if Effect = dropsource.DROPEFFECT_MOVE then // remove the data we just dropped from active document end if end if End EventHandler
Property DragStarted As Boolean
Property dropsource As PictureDragSource
End Class
Class PictureDragSource Inherits WindowsDragSourceMBS
EventHandler Function GiveFeedback(Effect as integer) As integer Return DRAGDROP_S_USEDEFAULTCURSORS End EventHandler
EventHandler Function QueryContinueDrag(EscapePressed as boolean, KeyState as integer) As integer if EscapePressed then Return DRAGDROP_S_CANCEL end if if Bitwise.BitAnd(KeyState, MK_LBUTTON)=0 then return DRAGDROP_S_DROP end if Return S_OK End EventHandler
End Class
End Project

See also:

The items on this page are in the following plugins: MBS Win Plugin.


The biggest plugin in space...