ASut 0 Posted September 10, 2010 hi, i need some help with my code, the button flash all the time, how can i stop it? #include <GUIConstants.au3> $Form1 = GUICreate("Form1", 269, 179, 193, 115) $Checkbox = GUICtrlCreateCheckbox("checkbox", 80, 48, 97, 17) $Button = GUICtrlCreateButton("Button", 96, 88, 75, 25, 0) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch if GUICtrlRead($checkbox)=$GUI_CHECKED then GUICtrlSetState($Button,$GUI_DISABLE) Else GUICtrlSetState($Button,$GUI_ENABLE) EndIf WEnd Share this post Link to post Share on other sites
kaotkbliss 146 Posted September 10, 2010 The problem I see is that each loop you set the state of the checkbox. Most likely why it's flickering. If you move your "If" condition to a seperate function and just check the state of the checkbox for change, you can then call the function if there is a change. That should remove the flickering. 010101000110100001101001011100110010000001101001011100110010000001101101011110010010000001110011011010010110011100100001My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueekWe're gonna need another Timmy! Share this post Link to post Share on other sites
Tvern 11 Posted September 10, 2010 You're constantly setting the state of the button, even if it is already in that state. Seen as the only thing that can change the button state is (un)checking the checkbox, you only have to change the button state when the checkbox is clicked. Like this: #include <GUIConstants.au3> $Form1 = GUICreate("Form1", 269, 179, 193, 115) $Checkbox = GUICtrlCreateCheckbox("checkbox", 80, 48, 97, 17) $Button = GUICtrlCreateButton("Button", 96, 88, 75, 25, 0) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Checkbox If GUICtrlRead($Checkbox)=$GUI_CHECKED then GUICtrlSetState($Button,$GUI_DISABLE) Else GUICtrlSetState($Button,$GUI_ENABLE) EndIf EndSwitch WEnd Share this post Link to post Share on other sites
ASut 0 Posted September 10, 2010 thanks for the help,it works fine. Share this post Link to post Share on other sites
ASut 0 Posted September 10, 2010 You're constantly setting the state of the button, even if it is already in that state. Seen as the only thing that can change the button state is (un)checking the checkbox, you only have to change the button state when the checkbox is clicked. Like this: #include <GUIConstants.au3> $Form1 = GUICreate("Form1", 269, 179, 193, 115) $Checkbox = GUICtrlCreateCheckbox("checkbox", 80, 48, 97, 17) $Button = GUICtrlCreateButton("Button", 96, 88, 75, 25, 0) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Checkbox If GUICtrlRead($Checkbox)=$GUI_CHECKED then GUICtrlSetState($Button,$GUI_DISABLE) Else GUICtrlSetState($Button,$GUI_ENABLE) EndIf EndSwitch WEnd but how about i need to check two or more checkboxes state,e.g checkbox1 and checkbox2 are both unchecked then button become disable, for other case button enable? Share this post Link to post Share on other sites
Tvern 11 Posted September 10, 2010 Add the seconds checkbox to the case, so when either checkbox is clicked the state of the button is updated. Case $Checkbox, $Checkbox2 ... Add the second checkbox to the if statement, so it will only be true if both checkboxes are unchecked. If GUICtrlRead($Checkbox)=$GUI_UNCHECKED And GUICtrlRead($Checkbox2)=$GUI_UNCHECKED Then ... Share this post Link to post Share on other sites
ASut 0 Posted September 10, 2010 Add the seconds checkbox to the case, so when either checkbox is clicked the state of the button is updated. Case $Checkbox, $Checkbox2 ... Add the second checkbox to the if statement, so it will only be true if both checkboxes are unchecked. If GUICtrlRead($Checkbox)=$GUI_UNCHECKED And GUICtrlRead($Checkbox2)=$GUI_UNCHECKED Then ... thanks a lot,it works, I have try a lot of time and finally you sloved the problem within just few min. I found that this forum is very helpful. sorry for my poor English Share this post Link to post Share on other sites
apstanto 2 Posted September 10, 2010 thanks a lot,it works, I have try a lot of time and finally you sloved the problem within just few min. I found that this forum is very helpful.sorry for my poor EnglishYou're right about the forums! Lots of smart people willing to help Awesome! Share this post Link to post Share on other sites
Fubarable 1 Posted September 10, 2010 sorry for my poor EnglishTo me, your English is fine. Share this post Link to post Share on other sites