=sinister= Posted November 12, 2005 Share Posted November 12, 2005 is there any way I can make an image, that i set using GUI, drag-able? Really apreciate some help! Thanks! Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 13, 2005 Moderators Share Posted November 13, 2005 You could take a look at mousegetpos(), and use the coords after an _IsPressed as the coords to the picture to possibly move it. I remember Cyberslug doing something similiar with resizing a lable with a similar method as above. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
CyberSlug Posted November 13, 2005 Share Posted November 13, 2005 I'm rusty, but this might help: #include <GuiConstants.au3> ; Constants for use with the return result of GUIGetCursorInfo ; so that I don't have to comment my code :) Global Const $X = 0, $Y = 1, $PRIMARY_DOWN = 2, $SECONDARY_DOWN = 3, $CTRL = 4 $GUI = GuiCreate("Example of mouse down and drag...") $label = GuiCtrlCreateLabel("This is a label", 10, 10, 100, 100) GuiCtrlSetBkColor($label, 0xFF0000) GuiSetState() While 1 $msg = GuiGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop $mouse = GUIGetCursorInfo($GUI) If $mouse[$PRIMARY_DOWN] And $mouse[$CTRL] = $label Then $LabelPos = ControlGetPos($GUI,"",$label) $lwidth = $LabelPos[2] $lheight = $LabelPos[3] GuiCtrlSetPos( $label, $mouse[$X] - $lwidth/2, $mouse[$Y] - $lheight/2 ) EndIf WEnd Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
layer Posted November 13, 2005 Share Posted November 13, 2005 (edited) Wasn't there like, a ReleaseCapture UDF that did this with like 1 simple DllCall... I know I used to have it somewhere here...EDIT: Nevermind, that's just if you want to move the WHOLE GUI, not a specific control. Although CyberSlug's example works very nicely. Edited November 13, 2005 by layer FootbaG Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 13, 2005 Moderators Share Posted November 13, 2005 Replaced: $label = GuiCtrlCreateLabel("This is a label", 10, 10, 100, 100) With: $label = GUICtrlCreatePic(@DocumentsCommonDir & "\My Pictures\Sample Pictures\Sunset.jpg", 50, 50, 50, 50) Works very nice !! Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
CyberSlug Posted November 13, 2005 Share Posted November 13, 2005 Revised code below. The original code would center the image under the mouse when you clicked. The code below is "better" in that you can drag the label near the corner; however, you might have to pick up the label again if you drag the mouse too quickly. #include <GuiConstants.au3> ; Constants for use with the return result of GUIGetCursorInfo ; so that I don't have to comment my code :) Global Const $X = 0, $Y = 1, $PRIMARY_DOWN = 2, $SECONDARY_DOWN = 3, $CTRL = 4 $GUI = GuiCreate("Example of mouse down and drag...") $label = GuiCtrlCreateLabel("This is a label", 10, 10, 100, 100) GuiCtrlSetBkColor($label, 0xFF0000) GuiSetState() Dim $xOffset, $yOffset While 1 $msg = GuiGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop $mouse = GUIGetCursorInfo($GUI) If $mouse[$PRIMARY_DOWN] And $mouse[$CTRL] = $label Then $LabelPos = ControlGetPos($GUI,"",$label) $lwidth = $LabelPos[2] $lheight = $LabelPos[3] GuiCtrlSetPos( $label, $mouse[$X] - $xOffset, $mouse[$Y] - $yOffset) Else $LabelPos = ControlGetPos($GUI,"",$label) $xOffset = $mouse[$X] - $labelPos[0];mouseX - labelX $yOffset = $mouse[$Y] - $labelPos[1];mouseY - labelY EndIf WEnd Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 13, 2005 Moderators Share Posted November 13, 2005 Nice one!!... He got his code last night and didn't even thank you... But I'm sure this will come in handy for someone... !! Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
cserindere Posted November 15, 2005 Share Posted November 15, 2005 Revised code below. The original code would center the image under the mouse when you clicked. The code below is "better" in that you can drag the label near the corner; however, you might have to pick up the label again if you drag the mouse too quickly.#include <GuiConstants.au3> ; Constants for use with the return result of GUIGetCursorInfo ; so that I don't have to comment my code :) Global Const $X = 0, $Y = 1, $PRIMARY_DOWN = 2, $SECONDARY_DOWN = 3, $CTRL = 4 $GUI = GuiCreate("Example of mouse down and drag...") $label = GuiCtrlCreateLabel("This is a label", 10, 10, 100, 100) GuiCtrlSetBkColor($label, 0xFF0000) GuiSetState() Dim $xOffset, $yOffset While 1 $msg = GuiGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop $mouse = GUIGetCursorInfo($GUI) If $mouse[$PRIMARY_DOWN] And $mouse[$CTRL] = $label Then $LabelPos = ControlGetPos($GUI,"",$label) $lwidth = $LabelPos[2] $lheight = $LabelPos[3] GuiCtrlSetPos( $label, $mouse[$X] - $xOffset, $mouse[$Y] - $yOffset) Else $LabelPos = ControlGetPos($GUI,"",$label) $xOffset = $mouse[$X] - $labelPos[0];mouseX - labelX $yOffset = $mouse[$Y] - $labelPos[1];mouseY - labelY EndIf WEndYou can fix the dropping the draged item by putting a Do loop following the If statementIf $mouse[$PRIMARY_DOWN] And $mouse[$CTRL] = $label Then Do $LabelPos = ControlGetPos($GUI,"",$label) $lwidth = $LabelPos[2] $lheight = $LabelPos[3] GuiCtrlSetPos( $label, $mouse[$X] - $xOffset, $mouse[$Y] - $yOffset) $mouse = GUIGetCursorInfo($GUI) Until Not $mouse[$PRIMARY_DOWN]Is there a way to avoid the screen flickering while moving the item? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now