找回密码
 加入
搜索
查看: 1676|回复: 2

[GUI管理] [已解决]controlmove移动控件后又自动归位了

[复制链接]
发表于 2012-6-22 20:58:41 | 显示全部楼层 |阅读模式
本帖最后由 1007236046 于 2012-6-22 21:57 编辑

#Include <Misc.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>

Example()

Func Example()
    Local $Button_1, $msg, $aPos, $aTemp
    $Form = GUICreate("My GUI Button") 

    $Button_1 = GUICtrlCreateButton("Button", 10, 30, 100, 30)
        $aButton_1 = ControlGetPos($Form, "", $Button_1)

    GUISetState() 

    ; Run the GUI until the dialog is closed
    While 1
                If _Hover($Form, $aButton_1[0], $aButton_1[1], $aButton_1[2], $aButton_1[3]) Then
                        While _IsPressed(1)
                                If Not IsArray($aPos) Then $aPos = MouseGetPos()
                                $aTemp = MouseGetPos()
                                If $aTemp[0] <> $aPos[0] Or $aTemp[1] <> $aPos[1] Then
                                        ControlMove($Form, "", $Button_1, $aButton_1[0]+($aTemp[0]-$aPos[0]), $aButton_1[1]+($aTemp[1]-$aPos[1]) )
                                EndIf
                        WEnd
                        $aButton_1 = ControlGetPos($Form, "", $Button_1)
                        $aPos = ""
                EndIf
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button_1
        EndSelect
    WEnd
EndFunc   ;==>Example

Func _Hover($cH_hWin = "", $Pos_X = 0, $Pos_Y = 0, $Pos_W = 0, $Pos_H = 0)
    $cH_Data = GUIGetCursorInfo($cH_hWin)
    If Not IsArray($cH_Data) Then Return SetError(10086)
    If $cH_Data[0] > $Pos_X And $cH_Data[0] < $Pos_X + $Pos_W And $cH_Data[1] > $Pos_Y And $cH_Data[1] < $Pos_Y + $Pos_H Then
        Return 1 
    Else
                Return 0
    EndIf
EndFunc

这是在论坛找的控件移动方法。
有个问题,控件移动后,再最小化窗口和还原,控件又回到创建时候的位置了
换用2楼的函数可以了
发表于 2012-6-22 21:52:09 | 显示全部楼层
用GUICtrlSetPos吧
发表于 2012-6-22 22:42:50 | 显示全部楼层
学习了。
#include <Misc.au3>
#include <GUIConstantsEx.au3>
$Form = GUICreate("My GUI Button")
$Button = GUICtrlCreateButton("Button", 10, 30, 100, 30)
GUISetState()
While 1
        $msg = GUIGetMsg()
        Switch $msg
                Case $GUI_EVENT_CLOSE
                        Exit
        EndSwitch
        If Not BitAND(WinGetState($Form), 16) Then
                $mxia = GUIGetCursorInfo()
                If $mxia[4] = $Button And _IsPressed(1) Then
                        $bpos = ControlGetPos($Form, "", $Button)
                        $mpos = MouseGetPos()
                        While _IsPressed(1)
                                $mpos2 = MouseGetPos()
                        WEnd
                        GUICtrlSetPos($Button, $bpos[0] + $mpos2[0] - $mpos[0], $bpos[1] + $mpos2[1] - $mpos[1])
                EndIf
        EndIf
WEnd
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-18 14:12 , Processed in 0.083246 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表