本帖最后由 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楼的函数可以了 |