官网一个很酷的实例:按钮自由伸缩
#include <GUIConstants.au3>
#include <StaticConstants.au3>
$GUI = GUICreate("..Drag Test..")
GUISetBkColor(0x0000ff)
$item1 = GUICtrlCreateButton(" Drag Me", 100, 100, 200, 50)
;~DRAG CONTROLS
Local $LastClick, $SquareResizers, $Hover = -1337
$DragOverlay = GUICtrlCreateLabel("", -99, -99, 1, 1, $SS_BLACKFRAME)
$SquareResizers = GUICtrlCreateLabel("", 0, 0, 5, 5)
GUICtrlSetCursor(-1, 12)
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlSetState(-1,$GUI_HIDE)
$SquareResizers = GUICtrlCreateLabel("", 0, 0, 5, 5)
GUICtrlSetCursor(-1, 10)
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlSetState(-1,$GUI_HIDE)
$SquareResizers = GUICtrlCreateLabel("", 0, 0, 5, 5)
GUICtrlSetCursor(-1, 10)
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlSetState(-1,$GUI_HIDE)
$SquareResizers = GUICtrlCreateLabel("", 0, 0, 5, 5)
GUICtrlSetCursor(-1, 12)
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlSetState(-1,$GUI_HIDE)
$SquareResizers = GUICtrlCreateLabel("", 0, 0, 5, 5)
GUICtrlSetCursor(-1, 11)
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlSetState(-1,$GUI_HIDE)
$SquareResizers = GUICtrlCreateLabel("", 0, 0, 5, 5)
GUICtrlSetCursor(-1, 11)
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlSetState(-1,$GUI_HIDE)
GUISetState()
While 1
Sleep(15)
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
Case $msg = $SquareResizers
_GUICtrlResizeNE()
Case $msg = $SquareResizers
_GUICtrlResizeNW()
Case $msg = $SquareResizers
_GUICtrlResizeSE()
Case $msg = $SquareResizers
_GUICtrlResizeSW()
Case $msg = $SquareResizers
_GUICtrlResizeN()
Case $msg = $SquareResizers
_GUICtrlResizeS()
EndSelect
_GUICtrlDrag($Hover)
_GUICtrlDragOverlay()
WEnd
Func _GUICtrlDragOverlay()
$cursor = GUIGetCursorInfo()
If IsArray($cursor) Then
If $cursor <> 0 Then
If $cursor <> $SquareResizers AND $cursor <> $SquareResizers AND $cursor <> $SquareResizers AND $cursor <> $SquareResizers AND $cursor <> $SquareResizers AND $cursor <> $SquareResizers Then
$pos = ControlGetPos($GUI, "", $cursor)
$pos2 = ControlGetPos($GUI, "", $DragOverlay)
If $pos <> $pos2+1 AND $pos <> $pos2+1 AND $pos <> $pos2-2 AND $pos <> $pos2-2 Then
GUICtrlSetPos($DragOverlay, $pos-1, $pos-1, $pos+2, $pos+2)
GUICtrlSetState($DragOverlay, $GUI_SHOW)
GUICtrlSetState($cursor, $GUI_DISABLE)
$Hover = $cursor
EndIf
EndIf
Else
GUICtrlSetState($Hover, $GUI_ENABLE)
$Hover = -1337
GUICtrlSetPos($DragOverlay, -99, -99, 1, 1)
EndIf
EndIf
EndFunc
Func _GUICtrlResizeS()
GUISetCursor(11)
GUICtrlSetCursor($LastClick, 10)
GUICtrlSetState($DragOverlay, $GUI_HIDE)
$pos = ControlGetPos($GUI, "", $LastClick)
Do
Sleep(5)
$cursor = GUIGetCursorInfo()
GUICtrlSetPos($LastClick, $pos, $pos, $pos, ($cursor-$pos))
$pos = ControlGetPos($GUI, "", $LastClick)
GUICtrlSetPos($SquareResizers, $pos-3, $pos+$pos)
GUICtrlSetPos($SquareResizers, ($pos+$pos)-2, $pos+$pos)
GUICtrlSetPos($SquareResizers, (($pos+$pos)-($pos/2)), $pos+$pos)
Until $cursor = 0
GUICtrlSetCursor($LastClick, 2)
GUISetCursor(2)
EndFunc
Func _GUICtrlResizeN()
GUISetCursor(11)
GUICtrlSetCursor($LastClick, 11)
GUICtrlSetState($DragOverlay, $GUI_HIDE)
$pos = ControlGetPos($GUI, "", $LastClick)
Do
Sleep(5)
$cursor = GUIGetCursorInfo()
GUICtrlSetPos($LastClick, $pos, $pos-($pos-$cursor), $pos, $pos+($pos-$cursor))
$pos = ControlGetPos($GUI, "", $LastClick)
GUICtrlSetPos($SquareResizers, $pos-2, $pos-5)
GUICtrlSetPos($SquareResizers, ($pos+$pos)-2, $pos-5)
GUICtrlSetPos($SquareResizers, (($pos+$pos)-($pos/2)), $pos-5)
Until $cursor = 0
GUICtrlSetCursor($LastClick, 2)
GUISetCursor(2)
EndFunc
Func _GUICtrlResizeSE()
GUISetCursor(10)
GUICtrlSetCursor($LastClick, 10)
GUICtrlSetState($DragOverlay, $GUI_HIDE)
$pos = ControlGetPos($GUI, "", $LastClick)
Do
Sleep(5)
$cursor = GUIGetCursorInfo()
GUICtrlSetPos($LastClick, $pos-($pos-$cursor), $pos, ($pos-$cursor)+$pos, ($cursor-$pos))
$pos = ControlGetPos($GUI, "", $LastClick)
GUICtrlSetPos($SquareResizers, $pos-2, $pos-5)
GUICtrlSetPos($SquareResizers, $pos-3, $pos+$pos)
GUICtrlSetPos($SquareResizers, ($pos+$pos)-2, $pos+$pos)
GUICtrlSetPos($SquareResizers, (($pos+$pos)-($pos/2)), $pos-5)
GUICtrlSetPos($SquareResizers, (($pos+$pos)-($pos/2)), $pos+$pos)
Until $cursor = 0
GUICtrlSetCursor($LastClick, 2)
GUISetCursor(2)
EndFunc
Func _GUICtrlResizeNW()
GUISetCursor(10)
GUICtrlSetCursor($LastClick, 10)
GUICtrlSetState($DragOverlay, $GUI_HIDE)
$pos = ControlGetPos($GUI, "", $LastClick)
Do
Sleep(5)
$cursor = GUIGetCursorInfo()
GUICtrlSetPos($LastClick, $pos, $pos-($pos-$cursor), $cursor-$pos, $pos+($pos-$cursor))
$pos = ControlGetPos($GUI, "", $LastClick)
GUICtrlSetPos($SquareResizers, $pos-2, $pos-5)
GUICtrlSetPos($SquareResizers, ($pos+$pos)-2, $pos-5)
GUICtrlSetPos($SquareResizers, $pos-3, $pos+$pos)
GUICtrlSetPos($SquareResizers, ($pos+$pos)-2, $pos+$pos)
GUICtrlSetPos($SquareResizers, (($pos+$pos)-($pos/2)), $pos-5)
GUICtrlSetPos($SquareResizers, (($pos+$pos)-($pos/2)), $pos+$pos)
Until $cursor = 0
GUICtrlSetCursor($LastClick, 2)
GUISetCursor(2)
EndFunc
Func _GUICtrlResizeNE()
GUISetCursor(12)
GUICtrlSetCursor($LastClick, 12)
GUICtrlSetState($DragOverlay, $GUI_HIDE)
$pos = ControlGetPos($GUI, "", $LastClick)
$XStayPos = $pos+$pos
$YStayPos = $pos+$pos
Do
Sleep(5)
$cursor = GUIGetCursorInfo()
If $cursor > $XStayPos Then $cursor = $XStayPos
If $cursor > $YStayPos Then $cursor = $YStayPos
GUICtrlSetPos($LastClick, $cursor, $cursor, $XStayPos-$cursor, $YStayPos-$cursor)
$pos = ControlGetPos($GUI, "", $LastClick)
GUICtrlSetPos($SquareResizers, $pos-2, $pos-5)
GUICtrlSetPos($SquareResizers, ($pos+$pos)-2, $pos-5)
GUICtrlSetPos($SquareResizers, $pos-3, $pos+$pos)
GUICtrlSetPos($SquareResizers, (($pos+$pos)-($pos/2)), $pos-5)
GUICtrlSetPos($SquareResizers, (($pos+$pos)-($pos/2)), $pos+$pos)
Until $cursor = 0
GUICtrlSetCursor($LastClick, 2)
GUISetCursor(2)
EndFunc
Func _GUICtrlResizeSW()
GUISetCursor(12)
GUICtrlSetCursor($LastClick, 12)
GUICtrlSetState($DragOverlay, $GUI_HIDE)
$pos = ControlGetPos($GUI, "", $LastClick)
Do
Sleep(5)
$cursor = GUIGetCursorInfo()
GUICtrlSetPos($LastClick, $pos, $pos, $cursor-$pos, $cursor-$pos)
$pos = ControlGetPos($GUI, "", $LastClick)
GUICtrlSetPos($SquareResizers, ($pos+$pos)-2, $pos+$pos)
GUICtrlSetPos($SquareResizers, ($pos+$pos)-2, $pos-5)
GUICtrlSetPos($SquareResizers, $pos-3, $pos+$pos)
GUICtrlSetPos($SquareResizers, (($pos+$pos)-($pos/2)), $pos-5)
GUICtrlSetPos($SquareResizers, (($pos+$pos)-($pos/2)), $pos+$pos)
Until $cursor = 0
GUICtrlSetCursor($LastClick, 2)
GUISetCursor(2)
EndFunc
Func _GUICtrlDrag($Control, $GridScale = 0)
Select
Case $msg = $DragOverlay
For $i = 0 To UBound($SquareResizers)-1
GUICtrlSetState($SquareResizers[$i], $GUI_HIDE)
Next
GUICtrlSetState($DragOverlay, $GUI_HIDE)
GUICtrlSetCursor($Control, 9)
$pos = ControlGetPos($GUI, "", $Control)
$cursor = GUIGetCursorInfo()
$XStayPos = $cursor-$pos
$YStayPos = $cursor-$pos
Do
Sleep(5)
$cursor = GUIGetCursorInfo()
$sX = $cursor-$XStayPos
$sY = $cursor-$YStayPos
If $GridScale <> 0 Then
$sX = Round($sX/$GridScale)*$GridScale
$sY = Round($sY/$GridScale)*$GridScale
EndIf
GUICtrlSetPos($Control, $sX, $sY)
Until $cursor = 0
GUICtrlSetCursor($Control, 2)
GUICtrlSetPos($SquareResizers, $sX-3, $sY-5)
GUICtrlSetPos($SquareResizers, ($sX+$pos)-2, $sY-5)
GUICtrlSetPos($SquareResizers, $sX-3, $sY+$pos)
GUICtrlSetPos($SquareResizers, ($sX+$pos)-2, $sY+$pos)
GUICtrlSetPos($SquareResizers, (($sX+$pos)-($pos/2)), $sY-5)
GUICtrlSetPos($SquareResizers, (($sX+$pos)-($pos/2)), $sY+$pos)
For $i = 0 To UBound($SquareResizers)-1
GUICtrlSetState($SquareResizers[$i], $GUI_SHOW)
Next
$pos = ControlGetPos($GUI, "", $cursor)
GUICtrlSetPos($DragOverlay, $pos-1, $pos-1, $pos+2, $pos+2)
GUICtrlSetState($DragOverlay, $GUI_SHOW)
$LastClick = $Control
EndSelect
EndFunc 不错。。。收藏了 一个字 强:face (13): 这也太师了吧
:face (3): 精品.......
顶......:
:face (31): . 好东西学习学习 这个要顶........ 不错。
强。。收藏了 一个钮要这么多码啊??? 路过 看下 :face (29): 收藏了 谢谢楼主:face (29): 很酷,谢谢帽子 帮助文件里面有个差不多的 提升 代码太多了!