Jump to content
Sign in to follow this  

GUI Drag and Drop Elements

Recommended Posts


I am trying to drag and drop an image from a box so that it locks into another box in the same window. Also if it is dropped outside one of the boxes I would like it to snap back to the original box (not complete yet).

On top of that I would like the images to be able to be able to use transparency or to be able to us a PNG. Which I was able to do with the Icons UDF:

However when dragging over the square box it shows the outline of the image.

I have found this helpful:

The program I am considering creating may have up to 30 boxes this way. Is this the most efficient way to do this?

Here is my modified code:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>

#Include <Icons.au3>

; Mouse coords relative to GUI client area
Opt("MouseCoordMode", 2)

; Set target coords
Global $iTgt_Left = 40, $iTgt_Top = 48, $iTgt_Right = 100, $iTgt_Bot = 108

#Region ### START Koda GUI section ### Form=
$hGUI = GUICreate("Drag and Drop Test", 344, 144, 192, 124)
;$Label1 = GUICtrlCreateLabel("", 40, 48, 60, 60, $SS_BLACKFRAME)
$Label1 = GUICtrlCreateLabel("", $iTgt_Left, $iTgt_Top, $iTgt_Right - $iTgt_Left, $iTgt_Bot - $iTgt_Top, $SS_BLACKFRAME)
$Label2 = GUICtrlCreateLabel("", 247, 47, 60, 60, $SS_BLACKFRAME)
;$Pic1 = GUICtrlCreatePic("C:Earth-icon.gif", 248, 48, 58, 58)
#EndRegion ### END Koda GUI section ###

;GUICtrlCreatePic('index.jpeg', 0, 0, 178, 192)
$Pic1 = GUICtrlCreatePic('', 248, 48, 58, 58)
_SetImage($Pic1, 'C:Earth-icon.gif')

;Test Box Dimentions
;MsgBox(1, "Test", $iTgt_Left & " & " & $iTgt_Top & " & " & $iTgt_Right - $iTgt_Left & " & " & $iTgt_Bot - $iTgt_Top)

While 1
Switch GUIGetMsg()
; If the mouse button is pressed - get info about where
$cInfo = GUIGetCursorInfo($hGUI)
; Is it over a control
$iControl = $cInfo[4]
Switch $iControl
; If it is a control we want to move
Case $Pic1
; Work out offset of mouse on control
$aPos = ControlGetPos($hGUI, "", $iControl)
$iSubtractX = $cInfo[0] - $aPos[0]
$iSubtractY = $cInfo[1] - $aPos[1]
; And then move the control until the mouse button is released
$cInfo = GUIGetCursorInfo($hGUI)
ControlMove($hGUI, "", $iControl, $cInfo[0] - $iSubtractX, $cInfo[1] - $iSubtractY)
Until Not $cInfo[2]
; See if the mouse was released over the target
$aMPos = MouseGetPos()
If $aMPos[0] > $iTgt_Left And $aMPos[0] < $iTgt_Right Then
If $aMPos[1] > $iTgt_Top And $aMPos[1] < $iTgt_Bot Then
Switch $iControl
Case $Pic1
ControlMove($hGUI, "", $iControl, $iTgt_Left + 1, $iTgt_Top + 1)
$sItem = "label"
MsgBox(0, "Info", "Over target with " & $sItem)


Thanks for any help!


Edited by StaticTank

Share this post

Link to post
Share on other sites

I'm looking for the same thing.

I want to build a GUI with ONE PNG ICON ONLY to accept drag and drop of files and folders so it pops up a context menu with "options" base on the file extension.

Kind of an "open with >" context menu.

For what i've been searching it's only possible to drag&drop to input texts in auto it.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this