Компьютерный форум OSzone.net  

Компьютерный форум OSzone.net (http://forum.oszone.net/index.php)
-   AutoIt (http://forum.oszone.net/forumdisplay.php?f=103)
-   -   [решено] Обработка значений Сheckbox в скрипте (http://forum.oszone.net/showthread.php?t=245879)

support23 31-10-2012 13:20 2015747

Обработка значений Сheckbox в скрипте
 
Добрый день!
Есть форма: чекбокс, 2 поля ввода, кнопка сохранить
1. Как сделать поля input1 и input2 доступными для записи только когда установлено значение чекбокса ?
2. Как считать значение чекбокса из ini файла, и при нажатии кнопки сохранить в ini файл с установленным в форме значением?

Код:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 266, 194, 423, 268)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 40, 32, 97, 17)
$Input1 = GUICtrlCreateInput("Input1", 40, 56, 121, 21)
$Input2 = GUICtrlCreateInput("Input2", 40, 88, 121, 21)
$Button1 = GUICtrlCreateButton("Save", 152, 128, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd


madmasles 31-10-2012 20:27 2016013

support23,
Попробуйте так.
Код:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>

Global $aInp[2] = ['First', 'Second'], $iChB, $aIni[3] = [@ScriptDir & '\test.ini', 'Checkbox', 'State'], _
        $aState[2][2] = [[BitOR($GUI_SS_DEFAULT_INPUT, $ES_READONLY), $GUI_UNCHECKED],[$GUI_SS_DEFAULT_INPUT, $GUI_CHECKED]]

$iChB = Abs(Int(IniRead($aIni[0], $aIni[1], $aIni[2], '0')))
If $iChB > 1 Then
    $iChB = 1
    IniWrite($aIni[0], $aIni[1], $aIni[2], $iChB)
EndIf

GUICreate('Test', 266, 194)
$nCheckbox = GUICtrlCreateCheckbox('Checkbox', 40, 32, 97, 17)
GUICtrlSetState(-1, $aState[$iChB][1])
For $i = 0 To 1
    $aInp[$i] = GUICtrlCreateInput($aInp[$i], 40, 56 + $i * 22, 121, 21, $aState[$iChB][0])
Next
;$nButton = GUICtrlCreateButton('Save', 152, 128, 75, 25)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $nCheckbox
            $iChB = BitAND(GUICtrlRead($nCheckbox), $GUI_CHECKED)
            For $i = 0 To 1
                GUICtrlSetStyle($aInp[$i], $aState[$iChB][0])
            Next
            IniWrite($aIni[0], $aIni[1], $aIni[2], $iChB)
            ;Case $nButton
            ;IniWrite(@ScriptDir & '\test.ini', 'Checkbox', 'State', $iChB)
    EndSwitch
WEnd


support23 01-11-2012 09:32 2016320

Спасибо, идеально!


Время: 01:32.

Время: 01:32.
© OSzone.net 2001-