[已解决]controlmove移动控件后又自动归位了
本帖最后由 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, $aButton_1, $aButton_1, $aButton_1) Then
While _IsPressed(1)
If Not IsArray($aPos) Then $aPos = MouseGetPos()
$aTemp = MouseGetPos()
If $aTemp <> $aPos Or $aTemp <> $aPos Then
ControlMove($Form, "", $Button_1, $aButton_1+($aTemp-$aPos), $aButton_1+($aTemp-$aPos) )
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 > $Pos_X And $cH_Data < $Pos_X + $Pos_W And $cH_Data > $Pos_Y And $cH_Data < $Pos_Y + $Pos_H Then
Return 1
Else
Return 0
EndIf
EndFunc
这是在论坛找的控件移动方法。
有个问题,控件移动后,再最小化窗口和还原,控件又回到创建时候的位置了
换用2楼的函数可以了 用GUICtrlSetPos吧 学习了。#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 = $Button And _IsPressed(1) Then
$bpos = ControlGetPos($Form, "", $Button)
$mpos = MouseGetPos()
While _IsPressed(1)
$mpos2 = MouseGetPos()
WEnd
GUICtrlSetPos($Button, $bpos + $mpos2 - $mpos, $bpos + $mpos2 - $mpos)
EndIf
EndIf
WEnd
页:
[1]