- Offizieller Beitrag
Jeder kennt das:
Entwicklung eines Projektes, es kommen immer mehr Control hinzu und die Gui muss angepasst werden, was auch bedeutet, dass alle(viele) Controlpositionen angepasst werden müssen.
Das war mir jetzt zu blöd und deshalb habe ich diese kleine Funktion zum Positionieren der Control geschrieben. Somit kann die Änderung bei Controls deutlich minimiert werden.
AutoIt: _CtrlPosRelative( )
;-- TIME_STAMP 2020-10-29 12:22:58
#include <WinAPISysWin.au3>
#include <WinAPIDlg.au3>
Opt('MustDeclareVars', 1)
GUICreate('Test')
Local $bt1 = GUICtrlCreateButton('Test Button 1', 0, 0, 150, 25)
_CtrlPosRelative(-1, -10, -10) ; 10px Rand rechts und unten
Local $bt2 = GUICtrlCreateButton('Test Button 2', 0, 0, 150, 25)
_CtrlPosRelative(-1, 10, -10) ; x ist fix, y relativ mit 10px Rand unten
GUISetState()
; Größe der Gui ändern und Ctrl verschieben an relative Position
Sleep(5000)
WinMove('Test', '', 100, 50, 800, 600)
_CtrlPosRelative($bt1, -10, -10)
_CtrlPosRelative($bt2, 10, -10)
Do
Until GUIGetMsg() = -3
Func _CtrlPosRelative($_iID, $_x, $_y, $_w=-1, $_h=-1)
Local $hCtrl = IsHWnd($_iID) ? $_iID : GUICtrlGetHandle($_iID)
Local $hParent = _WinAPI_GetParent($hCtrl)
Local $iID = _WinAPI_GetDlgCtrlID($hCtrl)
Local $aSize = ControlGetPos($hParent, '', $iID)
If $_w = -1 Or $_w = Default Then $_w = $aSize[2]
If $_h = -1 Or $_h = Default Then $_h = $aSize[3]
Local $clientW = _WinAPI_GetClientWidth($hParent)
Local $clientH = _WinAPI_GetClientHeight($hParent)
If $_x < 0 Then $_x = $clientW - $_w - Abs($_x)
If $_y < 0 Then $_y = $clientH - $_h - Abs($_y)
ControlMove($hParent, '', $iID, $_x, $_y, $_w, $_h)
EndFunc
Alles anzeigen