找回密码
 加入
搜索
查看: 2950|回复: 6

[GUI管理] 能否随意移动控件

  [复制链接]
发表于 2011-1-25 08:52:50 | 显示全部楼层 |阅读模式
能否拖住控件在窗口内随意移动?窗口不动!
发表于 2011-1-25 14:49:50 | 显示全部楼层
本帖最后由 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[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

评分

参与人数 1金钱 +30 收起 理由
3mile + 30 不错

查看全部评分

发表于 2011-1-25 20:09:46 | 显示全部楼层
楼上很给力啊, 谢谢分享。
 楼主| 发表于 2011-1-26 13:10:31 | 显示全部楼层
回复 2# smartzbs

谢谢smartzbs,您的代码非常好,不过我想再问一下,基于事件模式(OnEvent)下,如何写?我真是太笨了,老写不好。
发表于 2011-1-28 17:54:11 | 显示全部楼层
很强悍,顶一个。。
发表于 2011-1-29 10:44:27 | 显示全部楼层
强悍啊学习啦。。呵呵
发表于 2011-2-1 13:27:16 | 显示全部楼层
谢谢分享,把他应用到软件界面里不知如何
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-9 07:58 , Processed in 0.080246 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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