Guten Morgen!
Vorgeschichte
Ich bin gerade dabei ein Ausleseprogramm zu schreiben, bei dem man am Anfang in einer Combobox auswählen muss, wie viel Labels und Inputs es haben soll. Ich benutze also WinMove um die Größe des Fensters zu ändern, dabei fällt auf, dass sich nicht nur Controls (Labels, Inputs,...) verschieben, sondern auch ihre Größe verändert wird wie man z.B sehr schön mit Farbe sehen kann.
Ich fing also an mir eine kleine Funktion zu schreiben, welche die Position, Weite und Höhe eines Controls beibehält, sodass nur das Fenster verändert wird.
Problem:
Spoiler anzeigen
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <array.au3>
Global $height = 300
Global $width = 400
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 300, 400, 600, 120)
$hForm1 = WinGetHandle($Form1)
$Button1 = GUICtrlCreateButton("Button1", 40, 240, 225, 97)
$Label1 = GUICtrlCreateLabel("Label1", 40, 60, 80, 20)
GUICtrlSetBkColor(-1, 0x000FF)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $button1
$height = $height + 50
$width = $width + 50
_ComboChangePos($Form1, $Label1,$height, $width)
EndSwitch
WEnd
Func _ComboChangePos($Title, $controlID, $NewHeight, $NewWidth)
$NewHeight = $NewHeight +6
$NewWidth = $NewWidth +28
$GetTitlePos = WinGetPos($Title)
$GetControlPos = ControlGetPos($Title,"", $controlID)
WinMove($Title,"", $GetTitlePos[0],$GetTitlePos[1], $NewHeight, $NewWidth,1)
GUICtrlSetPos($controlID, $GetControlPos[0], $GetControlPos[1], $GetControlPos[2]-1, $GetControlPos[3])
EndFunc
Fragt ihr euch wieso ich denn in der Zeile 38 bei $GetControlPos[2] die -1 eingefügt habe?
Weil wenn man die -1 herauslöscht, bekommt man beim ersten Klick auf den Button total falsche Werte wie man im folgenden Script sehen kann. (Ab dem zweiten Klick funktioniert es.)
Spoiler anzeigen
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <array.au3>
Global $height = 300
Global $width = 400
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 300, 400, 600, 120)
$hForm1 = WinGetHandle($Form1)
$Button1 = GUICtrlCreateButton("Button1", 40, 240, 225, 97)
$Label1 = GUICtrlCreateLabel("Label1", 40, 60, 80, 20)
GUICtrlSetBkColor(-1, 0x000FF)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $button1
$height = $height + 50
$width = $width + 50
_ComboChangePos($Form1, $Label1,$height, $width)
EndSwitch
WEnd
Func _ComboChangePos($Title, $controlID, $NewHeight, $NewWidth)
$NewHeight = $NewHeight +6
$NewWidth = $NewWidth +28
$GetTitlePos = WinGetPos($Title)
$GetControlPos = ControlGetPos($Title,"", $controlID)
_ArrayDisplay($GetControlPos)
WinMove($Title,"", $GetTitlePos[0],$GetTitlePos[1], $NewHeight, $NewWidth,1)
GUICtrlSetPos($controlID, $GetControlPos[0], $GetControlPos[1], $GetControlPos[2], $GetControlPos[3])
$GetControlPos = ControlGetPos($Title,"", $controlID)
_ArrayDisplay($GetControlPos)
EndFunc