Jump to content
Sign in to follow this  
friends

How to toggle a butotn on / off ?

Recommended Posts

Piece of cake. Here it is:

#include <GUIConstants.au3>
AutoItSetOption("TrayIconDebug", 1)

;Initialize variables
Global $style1
Global $IniFile
Global $GUIWidth
Global $GUIHeight

$GUIWidth = 250
$GUIHeight = 250
$IniFile = StringTrimRight(@ScriptFullPath, 3) & "ini"

;Only a close button:
;$style1 = BitOR($WS_POPUP, $WS_CAPTION, $WS_SYSMENU)
;GUICreate("New GUI", $GUIWidth, $GUIHeight, -1, -1, $style1)

HotKeySet("{F5}", "SwapButton")

GUICreate("Swap Button", $GUIWidth, $GUIHeight)
   $button_1 = GUICtrlCreateButton("OK", 50, 150, 70, 20)

GUISetState(@SW_SHOW)

While 1
   Sleep(25)
   $msg = GUIGetMsg()
   Select
   
      Case $msg = $GUI_EVENT_CLOSE
         GUIDelete()
         Exit

   EndSelect

WEnd

Func SwapButton()
   If NOT IsDeclared("ButtonState") Then Global $ButtonState = "On"
   If $ButtonState = "On" Then
      $ButtonState = "Off"
      GUICtrlSetState($button_1, $GUI_DISABLE)
   ElseIf $ButtonState = "Off" Then
      $ButtonState = "On"
      GUICtrlSetState($button_1, $GUI_ENABLE)
   EndIf
EndFunc

Share this post


Link to post
Share on other sites

SlimShady, thanks for prompt feedback.

I know you're always being a helpful guy !

Edited by friends

Share this post


Link to post
Share on other sites

Just as an alternative: You could test the current state to swap like:

Func SwapButton()
  If GUICtrlGetState($button_1) = $GUI_ENABLE Then 
     GUICtrlSetState($button_1, $GUI_DISABLE)
  Else
     GUICtrlSetState($button_1, $GUI_ENABLE)
  EndIf
EndFunc
Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Just as an alternative: You could test the current state to swap like:

Func SwapButton()
  If GUICtrlGetState($button_1) = $GUI_ENABLE Then 
     GUICtrlSetState($button_1, $GUI_DISABLE)
  Else
     GUICtrlSetState($button_1, $GUI_ENABLE)
  EndIf
EndFunc

<{POST_SNAPBACK}>

Thanks JdeB.... I will try it out. :)

Share this post


Link to post
Share on other sites

Great idea JdeB.

I tried it out and it didn't work so I tried to find out why.

Here's a modified version that works:

Func SwapButton()
   If GUICtrlGetState($button_1) = $GUI_ENABLE + $GUI_SHOW Then
      GUICtrlSetState($button_1, $GUI_DISABLE)
   Else
      GUICtrlSetState($button_1, $GUI_ENABLE)
   EndIf
EndFunc

Share this post


Link to post
Share on other sites

Great idea JdeB.

I tried it out and it didn't work so I tried to find out why.

Here's a modified version that works:

Func SwapButton()
   If GUICtrlGetState($button_1) = $GUI_ENABLE + $GUI_SHOW Then
      GUICtrlSetState($button_1, $GUI_DISABLE)
   Else
      GUICtrlSetState($button_1, $GUI_ENABLE)
   EndIf
EndFunc

<{POST_SNAPBACK}>

Yea... i didn't test it and didn't think of the other states it could have.

This version should only test for ENABLED state only:

Func SwapButton()
  If BitANd(GUICtrlGetState($button_1),$GUI_ENABLE) Then
     GUICtrlSetState($button_1, $GUI_DISABLE)
  Else
     GUICtrlSetState($button_1, $GUI_ENABLE)
  EndIf
EndFunc
Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...