Jump to content

help please (buttons)


benson
 Share

Recommended Posts

Im new in using AutoIt and i have a small problem, how do i disable or gray-out a button when a condition is not met? for example, a listbox has a default value "Select item", if the value isnt changed, the button should be grayed out unless the listvalue is changed.

thanks

Link to comment
Share on other sites

Im new in using AutoIt and i have a small problem, how do i disable or gray-out a button when a condition is not met? for example, a listbox has a default value "Select item", if the value isnt changed, the button should be grayed out unless the listvalue is changed.

thanks

$Frm_Main = GUICreate("Test", 300, 250)
$Listbox = GUICtrlCreateListBox("", 20, 10, 100, 100)
$Button = GUICtrlCreateButton("Test", 40, 120, 60, 30)
GUICtrlSetState($button, 144)
GUICtrlSetData($ListBox, "Select Item|Item 1|Item 2", "Select Item")

While 1
   $Msg = GUIGetMsg()
   Switch $Msg
      Case -3
         Exit
      Case $ListBox
         If GUICtrlRead($ListBox) = "Select Item" Then
            If GUI CtrlGetState($Button) < 144 Then GUICtrlSetState($Button, 144)
         Else
            If GUICtrlGetState($Button) <> 80 Then GUICtrlSetState($Button, 80)
         EndIf
   EndSwitch
Wend

You could also do this

$Frm_Main = GUICreate("Test", 300, 250)
$Listbox = GUICtrlCreateListBox("", 20, 10, 100, 100)
$Button = GUICtrlCreateButton("Test", 40, 120, 60, 30)
GUICtrlSetState($button, 144)
GUICtrlSetData($ListBox, "Select Item|Item 1|Item 2", "Select Item")

While 1
   $Msg = GUIGetMsg()
   If GUICtrlRead($ListBox) = "Select Item" Then
      If GUI CtrlGetState($Button) < 144 Then GUICtrlSetState($Button, 144)
   Else
      If GUICtrlGetState($Button) <> 80 Then GUICtrlSetState($Button, 80)
   EndIf
   Switch $Msg
      Case -3
         Exit
   EndSwitch
Wend

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!"

Link to comment
Share on other sites

#include <GUIConstants.au3>

GUICreate("My GUICtrlRead",250,180)

$n1     = GUICtrlCreateList("", 10, 10, -1, 100)
GUICtrlSetData(-1, "item1|item2|item3", "item1")

$n2     = GUICtrlCreateButton("Read", 10, 130,100,25)
GUICtrlSetState (-1, $gui_disable)

GUISetState ()

Do
    $msg = GUIGetMsg()
    If GUICtrlRead ($n1) =  "item2" Then
        If BitAND(GUICtrlGetState($n2), $GUI_ENABLE) <> $GUI_ENABLE Then
            GUICtrlSetState($n2, $GUI_ENABLE)
        EndIf
    EndIf
    If GUICtrlRead ($n1) <>  "item2" Then
        If BitAND(GUICtrlGetState($n2), $GUI_DISABLE) <> $GUI_DISABLE Then
            GUICtrlSetState($n2, $GUI_DISABLE)
        EndIf
    EndIf   
Until $msg = $GUI_EVENT_CLOSE

[quote]Baby you're all that I want, When you're lyin' here in my armsI'm findin' it hard to believe, We're in heavenAnd love is all that I need , And I found it there in your heartIt isn't too hard to see, We're in heaven .Bryan Adams[/quote].............................................................................[u]AUTOIT[/u]

Link to comment
Share on other sites

I should have pointed out that I use the second method more for Inputs to make sure that a control stays disabled until a string has been entered into the input.

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!"

Link to comment
Share on other sites

Thanks for the answers guys, they helped solve my problem, btw, i noticed "144" and "80" from the code below.

If GUICtrlRead($ListBox) = "Select Item" Then

If GUI CtrlGetState($Button) < 144 Then GUICtrlSetState($Button, 144)

Else

If GUICtrlGetState($Button) <> 80 Then GUICtrlSetState($Button, 80)

EndIf

What are they for?

Thanks

Link to comment
Share on other sites

Thanks for the answers guys, they helped solve my problem, btw, i noticed "144" and "80" from the code below.

If GUICtrlRead($ListBox) = "Select Item" Then

If GUI CtrlGetState($Button) < 144 Then GUICtrlSetState($Button, 144)

Else

If GUICtrlGetState($Button) <> 80 Then GUICtrlSetState($Button, 80)

EndIf

What are they for?

Thanks

I use actual values instead of the GUI constants. Thats all. 144 = 128 + 16 (Disabled + visible) and 80 = 64 + 16 (Enabled + visible). I never use the constants but in particular when I am using GUICtrlGetState().

BTW: $GUI_EVENT_CLOSE = -3

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!"

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...