ASut Posted September 10, 2010 Share 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 Link to comment Share on other sites More sharing options...
kaotkbliss Posted September 10, 2010 Share 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. 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! Link to comment Share on other sites More sharing options...
Tvern Posted September 10, 2010 Share 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 Link to comment Share on other sites More sharing options...
ASut Posted September 10, 2010 Author Share Posted September 10, 2010 thanks for the help,it works fine. Link to comment Share on other sites More sharing options...
ASut Posted September 10, 2010 Author Share 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? Link to comment Share on other sites More sharing options...
Tvern Posted September 10, 2010 Share 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 ... Link to comment Share on other sites More sharing options...
ASut Posted September 10, 2010 Author Share 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 Link to comment Share on other sites More sharing options...
apstanto Posted September 10, 2010 Share 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! Link to comment Share on other sites More sharing options...
Fubarable Posted September 10, 2010 Share Posted September 10, 2010 sorry for my poor EnglishTo me, your English is fine. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now