能否随意移动控件
能否拖住控件在窗口内随意移动?窗口不动! 本帖最后由 smartzbs 于 2011-1-25 16:18 编辑鼠标移到Button按钮上,按下鼠标左键不放拖动该按钮.#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# smartzbs
谢谢smartzbs,您的代码非常好,不过我想再问一下,基于事件模式(OnEvent)下,如何写?我真是太笨了,老写不好。 很强悍,顶一个。。 强悍啊学习啦。。呵呵 谢谢分享,把他应用到软件界面里不知如何
页:
[1]