Jump to content
Sign in to follow this  
john123

How to use Guictrlsetstate?

Recommended Posts

john123

Please help me a problem as below:

In Tab1, I want Apply button grey-out when Year combo box empty, and when I chose a year in year combo box,.it enable , press it to write a year to data.ini file. After that, I want Apply button grey-out.

Then I type a name in Name input (or new chose a year in combo box - Name input or year combo box get focus), I want Apply button enable.

And same for Tabl2.

I tried GuiCtrlSetState and ConsoleCommand but without success .

Thank you very much.

Here my code :

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

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form1", 413, 298, 300, 220)
$Tab1 = GUICtrlCreateTab(64, 32, 289, 193)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$TabSheet1 = GUICtrlCreateTabItem("Tab1")
$Name = GUICtrlCreateInput("", 168, 96, 113, 21)
$Year = GUICtrlCreateCombo("", 96, 96, 57, 25)
GUICtrlSetData(-1,"2006|2007|2008|2009","")
$Lable1 = GUICtrlCreateLabel("Year", 104, 72, 26, 17)
$Label2 = GUICtrlCreateLabel("Name", 200, 72, 32, 17)
$TabSheet2 = GUICtrlCreateTabItem("Tab2")
$Height = GUICtrlCreateInput("", 120, 96, 113, 21)
$Label3 = GUICtrlCreateLabel("Hieght", 88, 72, 35, 17)
$Label4 = GUICtrlCreateLabel("Weight", 88, 128, 38, 17)
$Weight = GUICtrlCreateInput("", 120, 152, 121, 21)
GUICtrlCreateTabItem("")
$OK = GUICtrlCreateButton("OK", 200, 232, 59, 25, 0)
$Apply = GUICtrlCreateButton("Apply", 272, 232, 51, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Apply
        
            Switch GUICtrlRead($Tab1)
                Case 0
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Year",GUICtrlRead($Year))
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Name",GUICtrlRead($Name))
                Case 1
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Height",GUICtrlRead($Height))
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Weight",GUICtrlRead($Weight))
                
            EndSwitch
            
        Case $OK    
            
            Switch GUICtrlRead($Tab1)
                Case 0
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Year",GUICtrlRead($Year))
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Name",GUICtrlRead($Name))
                    exit
                Case 1
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Height",GUICtrlRead($Height))
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Weight",GUICtrlRead($Weight)) 
                    exit
            EndSwitch
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites
cheese

no good :P , but it works!

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

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form1", 413, 298, 300, 220)
$Tab1 = GUICtrlCreateTab(64, 32, 289, 193)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$TabSheet1 = GUICtrlCreateTabItem("Tab1")
$Name = GUICtrlCreateInput("", 168, 96, 113, 21)
$Year = GUICtrlCreateCombo("", 96, 96, 57, 25)
GUICtrlSetData(-1,"2006|2007|2008|2009","")
$Lable1 = GUICtrlCreateLabel("Year", 104, 72, 26, 17)
$Label2 = GUICtrlCreateLabel("Name", 200, 72, 32, 17)
$TabSheet2 = GUICtrlCreateTabItem("Tab2")
$Height = GUICtrlCreateInput("", 120, 96, 113, 21)
$Label3 = GUICtrlCreateLabel("Hieght", 88, 72, 35, 17)
$Label4 = GUICtrlCreateLabel("Weight", 88, 128, 38, 17)
$Weight = GUICtrlCreateInput("", 120, 152, 121, 21)
GUICtrlCreateTabItem("")
$OK = GUICtrlCreateButton("OK", 200, 232, 59, 25, 0)
$Apply = GUICtrlCreateButton("Apply", 272, 232, 51, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;1=->
GUICtrlSetState($Apply,$GUI_DISABLE)
$valueYear = GUICtrlRead($Year)
$valueName = GUICtrlRead($Name)
$valueHeight = GUICtrlRead($Height)
$valueWeight = GUICtrlRead($Weight)
;<-=1

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Apply
            Switch GUICtrlRead($Tab1)
                Case 0
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Year",GUICtrlRead($Year))
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Name",GUICtrlRead($Name))
                Case 1
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Height",GUICtrlRead($Height))
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Weight",GUICtrlRead($Weight))
            EndSwitch
            ;2=->
            GUICtrlSetState($Apply,$GUI_DISABLE)
            $valueYear = GUICtrlRead($Year)
            $valueName = GUICtrlRead($Name)
            $valueHeight = GUICtrlRead($Height)
            $valueWeight = GUICtrlRead($Weight)
            ;<-=2
        Case $OK
            Switch GUICtrlRead($Tab1)
                Case 0
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Year",GUICtrlRead($Year))
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Name",GUICtrlRead($Name))
                    exit
                Case 1
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Height",GUICtrlRead($Height))
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Weight",GUICtrlRead($Weight))
                    exit
            EndSwitch
    EndSwitch
    ;3=->
    If ((GUICtrlRead($Year) <> $valueYear) Or (GUICtrlRead($Name) <> $valueName) Or _
        (GUICtrlRead($Height) <> $valueHeight) Or (GUICtrlRead($Weight) <> $valueWeight)) And _
        (GUICtrlGetState($Apply) = 128 + 16) Then; 128 + 16 = $GUI_ENABLE + ??
        GUICtrlSetState($Apply,$GUI_ENABLE)
    EndIf
    ;<-=3
WEnd

Share this post


Link to post
Share on other sites
john123

Thanks Cheese . Can you fix below problem?

When I click into dropdown list and drag mouse on list of combo but I don't chose any year and click outside combo box (that mean have no year in combo box - view picture), status of "Apply" button is Enable. Can you make it Disable?

Thank you.

Posted Image

Posted Image

Posted Image

Edited by john123

Share this post


Link to post
Share on other sites
Zedna

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

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form1", 413, 298, 300, 220)
$Tab1 = GUICtrlCreateTab(64, 32, 289, 193)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$TabSheet1 = GUICtrlCreateTabItem("Tab1")
$Name = GUICtrlCreateInput("", 168, 96, 113, 21)
$Year = GUICtrlCreateCombo("", 96, 96, 57, 25)
GUICtrlSetData(-1,"2006|2007|2008|2009","")
$Lable1 = GUICtrlCreateLabel("Year", 104, 72, 26, 17)
$Label2 = GUICtrlCreateLabel("Name", 200, 72, 32, 17)
$TabSheet2 = GUICtrlCreateTabItem("Tab2")
$Height = GUICtrlCreateInput("", 120, 96, 113, 21)
$Label3 = GUICtrlCreateLabel("Hieght", 88, 72, 35, 17)
$Label4 = GUICtrlCreateLabel("Weight", 88, 128, 38, 17)
$Weight = GUICtrlCreateInput("", 120, 152, 121, 21)
GUICtrlCreateTabItem("")
$OK = GUICtrlCreateButton("OK", 200, 232, 59, 25, 0)
$Apply = GUICtrlCreateButton("Apply", 272, 232, 51, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;1=->
GUICtrlSetState($Apply,$GUI_DISABLE)
$valueYear = GUICtrlRead($Year)
$valueName = GUICtrlRead($Name)
$valueHeight = GUICtrlRead($Height)
$valueWeight = GUICtrlRead($Weight)
;<-=1

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Apply
            Switch GUICtrlRead($Tab1)
                Case 0
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Year",GUICtrlRead($Year))
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Name",GUICtrlRead($Name))
                Case 1
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Height",GUICtrlRead($Height))
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Weight",GUICtrlRead($Weight))
            EndSwitch
            ;2=->
            GUICtrlSetState($Apply,$GUI_DISABLE)
            $valueYear = GUICtrlRead($Year)
            $valueName = GUICtrlRead($Name)
            $valueHeight = GUICtrlRead($Height)
            $valueWeight = GUICtrlRead($Weight)
            ;<-=2
        Case $OK
            Switch GUICtrlRead($Tab1)
                Case 0
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Year",GUICtrlRead($Year))
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Name",GUICtrlRead($Name))
                    exit
                Case 1
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Height",GUICtrlRead($Height))
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Weight",GUICtrlRead($Weight))
                    exit
            EndSwitch

    Case $Year,$Name,$Height,$Weight
        If GUICtrlRead($Year) <> '' And GUICtrlRead($Name) <> '' And _
            GUICtrlRead($Height) <> '' And GUICtrlRead($Weight) <> '' Then
            GUICtrlSetState($Apply,$GUI_ENABLE)
        Else
            GUICtrlSetState($Apply,$GUI_DISABLE)
        EndIf
     
 EndSwitch
  
WEnd

Share this post


Link to post
Share on other sites
GEOSoft

Quick tip to avoid flicker

Case $Year,$Name,$Height,$Weight
       If GUICtrlRead($Year) <> '' And GUICtrlRead($Name) <> '' And _
          GUICtrlRead($Height) <> '' And GUICtrlRead($Weight) <> '' Then
          If GUICtrlGetState($Apply) > $GUI_ENABLE Then GUICtrlSetState($Apply,$GUI_ENABLE)
       Else
          If GUICtrlGetState($Apply) < $GUI_DISABLE Then GUICtrlSetState($Apply,$GUI_DISABLE)
       EndIf

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
cheese

so, compare scripts john123, Zedna, GEOSoft and little mad from me :P

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

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form1",413,298,300,220)
$Tab1 = GUICtrlCreateTab(64,32,289,193)
GUICtrlSetResizing(-1,$GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
$TabSheet1 = GUICtrlCreateTabItem("Tab1")

$Label5 = GUICtrlCreateLabel("",66,55,283,41)
;GUICtrlSetBkColor(-1,0x00c0c0)
$Label6 = GUICtrlCreateLabel("",66,96,50,21)
;GUICtrlSetBkColor(-1,0xc0c000)
$Label7 = GUICtrlCreateLabel("",153,96,15,21)
;GUICtrlSetBkColor(-1,0xc0c000)
$Label8 = GUICtrlCreateLabel("",281,96,68,21)
;GUICtrlSetBkColor(-1,0xc0c000)
$Label9 = GUICtrlCreateLabel("",66,117,283,104)
;GUICtrlSetBkColor(-1,0x00c0c0)

$Name = GUICtrlCreateInput("",168,96,113,21)
$Year = GUICtrlCreateCombo("",96,96,57,25)
GUICtrlSetData(-1,"2006|2007|2008|2009","")
$Lable1 = GUICtrlCreateLabel("Year",104,72,26,17)
$Label2 = GUICtrlCreateLabel("Name",200,72,32,17)
$TabSheet2 = GUICtrlCreateTabItem("Tab2")

$Label10 = GUICtrlCreateLabel("",66,55,54,166)
;GUICtrlSetBkColor(-1,0x00c0c0)
$Label11 = GUICtrlCreateLabel("",120,55,121,41)
;GUICtrlSetBkColor(-1,0xc0c000)
$Label12 = GUICtrlCreateLabel("",120,117,121,35)
;GUICtrlSetBkColor(-1,0xc0c000)
$Label13 = GUICtrlCreateLabel("",120,173,121,48)
;GUICtrlSetBkColor(-1,0xc0c000)
$Label14 = GUICtrlCreateLabel("",241,55,108,166)
;GUICtrlSetBkColor(-1,0x00c0c0)

$Height = GUICtrlCreateInput("",120,96,121,21)
$Label3 = GUICtrlCreateLabel("Hieght",88,72,35,17)
$Label4 = GUICtrlCreateLabel("Weight",88,128,38,17)
$Weight = GUICtrlCreateInput("",120,152,121,21)
GUICtrlCreateTabItem("")
$OK = GUICtrlCreateButton("OK",200,232,59,25,0)
$Apply = GUICtrlCreateButton("Apply",272,232,51,25,0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUICtrlSetState($Apply,$GUI_DISABLE)
$valueYear = GUICtrlRead($Year)
$valueName = GUICtrlRead($Name)
$valueHeight = GUICtrlRead($Height)
$valueWeight = GUICtrlRead($Weight)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Apply
            Switch GUICtrlRead($Tab1)
                Case 0
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Year",GUICtrlRead($Year))
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Name",GUICtrlRead($Name))
                Case 1
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Height",GUICtrlRead($Height))
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Weight",GUICtrlRead($Weight))
            EndSwitch
            $valueYear = GUICtrlRead($Year)
            $valueName = GUICtrlRead($Name)
            $valueHeight = GUICtrlRead($Height)
            $valueWeight = GUICtrlRead($Weight)
            GUICtrlSetState($Apply,$GUI_DISABLE)
        Case $OK
            Switch GUICtrlRead($Tab1)
                Case 0
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Year",GUICtrlRead($Year))
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Name",GUICtrlRead($Name))
                    Exit
                Case 1
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Height",GUICtrlRead($Height))
                    IniWrite(@ScriptDir & '\data.ini',"INFO","Weight",GUICtrlRead($Weight))
                Exit
            EndSwitch
        Case $Year
            If GUICtrlRead($Year) <> $valueYear Then
                If GUICtrlGetState($Apply) > $GUI_ENABLE Then GUICtrlSetState($Apply,$GUI_ENABLE)
            Else
                If GUICtrlGetState($Apply) < $GUI_DISABLE Then GUICtrlSetState($Apply,$GUI_DISABLE)
            EndIf
        Case $Label5,$Label6,$Label7,$Label8,$Label9,$Label10,$Label11,$Label12,$Label13,$Label14;,$TabSheet1,$TabSheet2
            $valueYear = GUICtrlRead($Year)
            $valueName = GUICtrlRead($Name)
            $valueHeight = GUICtrlRead($Height)
            $valueWeight = GUICtrlRead($Weight)
            GUICtrlSetState($Apply,$GUI_DISABLE)
    EndSwitch
    If ((GUICtrlRead($Name) <> $valueName) Or (GUICtrlRead($Height) <> $valueHeight) Or (GUICtrlRead($Weight) <> $valueWeight)) _
    And GUICtrlGetState($Apply) > $GUI_DISABLE Then
        GUICtrlSetState($Apply,$GUI_ENABLE)
    EndIf
WEnd

Share this post


Link to post
Share on other sites
john123

Thanks very much. Cheese, Zedna, GEOSoft . . . I improve your code and it work fine. Thanks again.

Have a nice day.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.