PDA

Показать полную графическую версию : [решено] Обработка значений Сheckbox в скрипте


support23
31-10-2012, 13:20
Добрый день!
Есть форма: чекбокс, 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
support23,
Попробуйте так.#include (http://autoit-script.ru/autoit3_docs/keywords.htm##include) <EditConstants.au3>
#include (http://autoit-script.ru/autoit3_docs/keywords.htm##include) <GUIConstantsEx.au3>

Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) $aInp[2] = ['First', 'Second'], $iChB, $aIni[3] = [@ScriptDir (http://autoit-script.ru/autoit3_docs/macros.htm#@scriptdir) & '\test.ini', 'Checkbox', 'State'], _
$aState[2][2] = [[BitOR (http://autoit-script.ru/autoit3_docs/functions/BitOR.htm)($GUI_SS_DEFAULT_INPUT, $ES_READONLY), $GUI_UNCHECKED],[$GUI_SS_DEFAULT_INPUT, $GUI_CHECKED]]

$iChB = Abs (http://autoit-script.ru/autoit3_docs/functions/Abs.htm)(Int (http://autoit-script.ru/autoit3_docs/functions/Int.htm)(IniRead (http://autoit-script.ru/autoit3_docs/functions/IniRead.htm)($aIni[0], $aIni[1], $aIni[2], '0')))
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $iChB > 1 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
$iChB = 1
IniWrite (http://autoit-script.ru/autoit3_docs/functions/IniWrite.htm)($aIni[0], $aIni[1], $aIni[2], $iChB)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)

GUICreate (http://autoit-script.ru/autoit3_docs/functions/GUICreate.htm)('Test', 266, 194)
$nCheckbox = GUICtrlCreateCheckbox (http://autoit-script.ru/autoit3_docs/functions/GUICtrlCreateCheckbox.htm)('Checkbox', 40, 32, 97, 17)
GUICtrlSetState (http://autoit-script.ru/autoit3_docs/functions/GUICtrlSetState.htm)(-1, $aState[$iChB][1])
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 0 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) 1
$aInp[$i] = GUICtrlCreateInput (http://autoit-script.ru/autoit3_docs/functions/GUICtrlCreateInput.htm)($aInp[$i], 40, 56 + $i * 22, 121, 21, $aState[$iChB][0])
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
;$nButton = GUICtrlCreateButton('Save', 152, 128, 75, 25)
GUISetState (http://autoit-script.ru/autoit3_docs/functions/GUISetState.htm)()

While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) GUIGetMsg (http://autoit-script.ru/autoit3_docs/functions/GUIGetMsg.htm)()
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $nCheckbox
$iChB = BitAND (http://autoit-script.ru/autoit3_docs/functions/BitAND.htm)(GUICtrlRead (http://autoit-script.ru/autoit3_docs/functions/GUICtrlRead.htm)($nCheckbox), $GUI_CHECKED)
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 0 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) 1
GUICtrlSetStyle (http://autoit-script.ru/autoit3_docs/functions/GUICtrlSetStyle.htm)($aInp[$i], $aState[$iChB][0])
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
IniWrite (http://autoit-script.ru/autoit3_docs/functions/IniWrite.htm)($aIni[0], $aIni[1], $aIni[2], $iChB)
;Case $nButton
;IniWrite(@ScriptDir & '\test.ini', 'Checkbox', 'State', $iChB)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)

support23
01-11-2012, 09:32
Спасибо, идеально!




© OSzone.net 2001-2012