Jump to content
youtuber

Button flicker problem when checking radio

Recommended Posts

youtuber

Button is shaking when checking Radio

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 539, 438, 192, 124)
$Radio1 = GUICtrlCreateRadio("Radio1", 112, 80, 113, 17)
$Radio2 = GUICtrlCreateRadio("Radio2", 112, 120, 113, 17)
$Radio3 = GUICtrlCreateRadio("Radio3", 112, 160, 113, 17)
$Radio4 = GUICtrlCreateRadio("Radio4", 112, 200, 113, 17)
$Button1 = GUICtrlCreateButton("Button1", 112, 272, 75, 25)
GUICtrlSetState($Button1, $GUI_DISABLE)
GUISetState(@SW_SHOW)

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

        Case $nMsg = $Radio1 OR $nMsg = $Radio2 OR $nMsg = $Radio3 OR $nMsg = $Radio4
            If BitAND(GuiCtrlread($Radio1), $GUI_CHECKED) OR BitAND(GuiCtrlread($Radio2), $GUI_CHECKED) OR BitAND(GuiCtrlread($Radio3), $GUI_CHECKED) OR BitAND(GuiCtrlread($Radio4),$GUI_CHECKED) Then
                GUICtrlSetState($Button1,$GUI_ENABLE)
            else
                GUICtrlSetState($Button1,$GUI_DISABLE)
            EndIf
        Case $Button1
            MsgBox(0,"Clicked!","Clicked OK",3)
            GUICtrlSetState($Radio1,$gui_UNCHECKED)
            GUICtrlSetState($Radio2,$gui_UNCHECKED)
            GUICtrlSetState($Radio3,$gui_UNCHECKED)
            GUICtrlSetState($Radio4,$gui_UNCHECKED)
            GUICtrlSetState($Button1,$GUI_DISABLE)
    EndSwitch
WEnd

 

Share this post


Link to post
Share on other sites
Danyfirex

The correct way is.

Case $Radio1, $Radio2, $Radio3, $Radio4

 

Saludos

  • Like 2

Share this post


Link to post
Share on other sites
spudw2k

In your example, you could also do 

Case $Radio1 To $Radio4

as long as the radio buttons are created in sequence order and no other controls in between (because each control is assigned an integer index which increments by 1 each time).

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 539, 438, 192, 124)
$Radio1 = GUICtrlCreateRadio("Radio1", 112, 80, 113, 17)
$Radio2 = GUICtrlCreateRadio("Radio2", 112, 120, 113, 17)
$Radio3 = GUICtrlCreateRadio("Radio3", 112, 160, 113, 17)
$Radio4 = GUICtrlCreateRadio("Radio4", 112, 200, 113, 17)
$Button1 = GUICtrlCreateButton("Button1", 112, 272, 75, 25)
GUICtrlSetState($Button1, $GUI_DISABLE)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Radio1 To $Radio4
            If BitAND(GUICtrlRead($nMsg), $GUI_CHECKED) Then
                GUICtrlSetState($Button1,$GUI_ENABLE)
            Else
                GUICtrlSetState($Button1,$GUI_DISABLE)
            EndIf
        Case $Button1
            MsgBox(0,"Clicked!","Clicked OK",3)
            GUICtrlSetState($Radio1,$gui_UNCHECKED)
            GUICtrlSetState($Radio2,$gui_UNCHECKED)
            GUICtrlSetState($Radio3,$gui_UNCHECKED)
            GUICtrlSetState($Radio4,$gui_UNCHECKED)
            GUICtrlSetState($Button1,$GUI_DISABLE)
    EndSwitch
WEnd

However, Danyfirex is right, you'll likely want to evaluate each radio button on it's own.
 

Also, there's not much point evaluating if a radio button is checked if clicking it is what triggered the event, unless I'm not considering / overlooking something?

  • Like 2

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

×