Sign in to follow this  
Followers 0
ASut

need help with gui

9 posts in this topic

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



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 game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

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

thanks for the help,it works fine. ;)

Share this post


Link to post
Share on other sites

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

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

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

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

You're right about the forums! Lots of smart people willing to help ;) Awesome!

Share this post


Link to post
Share on other sites

sorry for my poor English

To me, your English is fine.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0