Что нового

Изменение размера Form после нажатия на Button

scanfail

Знающий
Сообщения
244
Репутация
17
Например, я представляю пользователю возможность добавить новый пункт, но когда добавиться этот новый пункт(вместе с новыми label и т.д.) мне понадобиться изменение Form-ы. Можно примеры?
 

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8,671
Репутация
2,481
scanfail [?]
Код:
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIButton.au3>

Global $sOld_Opt_GRM = Opt("GUIResizeMode", $GUI_DOCKALL)
Global $iGUI_Height = 200

Global $iExpndIndx = 14
Global $iCllpsIndx = 16

If StringRegExp(@OSVersion, "^WIN_(VISTA|7)$") Then
	$iExpndIndx += 1
	$iCllpsIndx += 1
EndIf

$hGUI = GUICreate("Expand GUI Example", 300, $iGUI_Height, -1, -1, -1, $WS_EX_TOOLWINDOW)
$nExpand_Button = GUICtrlCreateButton("  Expand", 20, 80, 80, 22) ;, $BS_ICON)
_GUICtrlButton_SetImage($nExpand_Button, @SystemDir & "\rasdlg.dll", $iExpndIndx)

#Region Expanded controls

GUICtrlCreateButton("Some Button", 20, 240, 80)
GUICtrlCreateButton("Other Button", 120, 240, 80)
GUICtrlCreateInput("Some Input", 20, 200, 200, 20)

#EndRegion Expanded controls

Opt("GUIResizeMode", $sOld_Opt_GRM)
GUISetState()

While 1
	$Msg = GUIGetMsg()
	
	Switch $Msg
		Case $GUI_EVENT_CLOSE
			_GUIImageList_Destroy($hImageList)
			Exit
		Case $nExpand_Button
			_Toggle_ExpandControls_Proc($hGUI, $iGUI_Height, $iGUI_Height + 80, $nExpand_Button)
	EndSwitch
WEnd

Func _Toggle_ExpandControls_Proc($hWnd, $iInitWndHeight, $iExpndHeight, $iExpndCtrlID, $sExpndText = "  Expand", $sCntrctText = "  Collapse")
	Local $iHeight, $sButtonText, $aSysCaptMetrics, $aSysBordMetrics
	
	Local $aWinSize = WinGetPos($hWnd)
	Local $aWinClientSize = WinGetClientSize($hWnd)
	
	Local $iBorderWidth = $aWinSize[2] - $aWinClientSize[0]
	Local $iCaptionHeight = $aWinSize[3] - $aWinClientSize[1] - $iBorderWidth
	
	If $aWinSize[3] > $iExpndHeight + $iCaptionHeight Then
		_GUICtrlButton_SetImage($nExpand_Button, @SystemDir & "\rasdlg.dll", $iExpndIndx)
		
		$iHeight = $iInitWndHeight + $iCaptionHeight + $iBorderWidth
		$sButtonText = $sExpndText
	Else
		_GUICtrlButton_SetImage($nExpand_Button, @SystemDir & "\rasdlg.dll", $iCllpsIndx)
		
		$iHeight = $iExpndHeight + $iCaptionHeight + $iBorderWidth
		$sButtonText = $sCntrctText
	EndIf
	
	GUICtrlSetData($iExpndCtrlID, $sButtonText)
	WinMove($hWnd, "", $aWinSize[0], $aWinSize[1], $aWinSize[2], $iHeight)
EndFunc
 
Автор
S

scanfail

Знающий
Сообщения
244
Репутация
17
Спасибо огромное за пример, но код какой-то большой... Мне бы простенький, нельзя упростить код как нибудь?
 

Black_Night

Новичок
Сообщения
67
Репутация
1
Интересно узнать, как плавно увеличить FORM (типо анимации)
Да, и хорошо былоб упростить код.. ;)
 

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8,671
Репутация
2,481
scanfail [?]
код какой-то большой
:blink:

Мне бы простенький, нельзя упростить код как нибудь?
Упростить в каком плане?
Что в нём сложного?


Black_Night [?]
как плавно увеличить FORM
это не совместимо с...
Да, и хорошо былоб упростить код
;)
Можно:

Код:
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIButton.au3>

Global $sOld_Opt_GRM = Opt("GUIResizeMode", $GUI_DOCKALL)
Global $iGUI_Height = 200

Global $iExpndIndx = 14
Global $iCllpsIndx = 16

If StringRegExp(@OSVersion, "^WIN_(VISTA|7)$") Then
    $iExpndIndx += 1
    $iCllpsIndx += 1
EndIf

$hGUI = GUICreate("Expand GUI Example", 300, $iGUI_Height, -1, -1, -1, $WS_EX_TOOLWINDOW)
$nExpand_Button = GUICtrlCreateButton("  Expand", 20, 80, 80, 22)
_GUICtrlButton_SetImage($nExpand_Button, @SystemDir & "\rasdlg.dll", $iExpndIndx)

GUICtrlCreateButton("Some Button", 20, 240, 80)
GUICtrlCreateButton("Other Button", 120, 240, 80)
GUICtrlCreateInput("Some Input", 20, 200, 200, 20)

Opt("GUIResizeMode", $sOld_Opt_GRM)
GUISetState()

While 1
    $Msg = GUIGetMsg()
    
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $nExpand_Button
            _Toggle_ExpandControls_Proc($hGUI, $iGUI_Height, $iGUI_Height + 80, $nExpand_Button)
    EndSwitch
WEnd

Func _Toggle_ExpandControls_Proc($hWnd, $iInitWndHeight, $iExpndHeight, $iExpndCtrlID, $sExpndText = "  Expand", $sCntrctText = "  Collapse")
    Local $iHeight, $sButtonText, $iStep = 1
	
    Local $aWinSize = WinGetPos($hWnd)
    Local $aWinClientSize = WinGetClientSize($hWnd)
    
    Local $iBorderWidth = $aWinSize[2] - $aWinClientSize[0]
    Local $iCaptionHeight = $aWinSize[3] - $aWinClientSize[1] - $iBorderWidth
    
    If $aWinSize[3] > $iExpndHeight + $iCaptionHeight Then
        _GUICtrlButton_SetImage($nExpand_Button, @SystemDir & "\rasdlg.dll", $iExpndIndx)
        
		$iHeight = $iInitWndHeight + $iCaptionHeight + $iBorderWidth
        $sButtonText = $sExpndText
		$iStep = -1
    Else
        _GUICtrlButton_SetImage($nExpand_Button, @SystemDir & "\rasdlg.dll", $iCllpsIndx)
        
        $iHeight = $iExpndHeight + $iCaptionHeight + $iBorderWidth
        $sButtonText = $sCntrctText
    EndIf
    
    GUICtrlSetData($iExpndCtrlID, $sButtonText)
	
	For $i = $aWinSize[3] To $iHeight Step $iStep
		WinMove($hWnd, "", $aWinSize[0], $aWinSize[1], $aWinSize[2], $i)
		
		$iTimer = TimerInit()
		Do
		Until TimerDiff($iTimer) > 2
	Next
EndFunc
 
Верх