Jump to content

Recommended Posts

Posted

Hey there,

e.g. I have a gui with one button. If i click the button it should turn transparency on and if i click it again it should turn transaprenc off, but how do i do that? or another example: If i click the button first time it should msgbox: "1" and for the second time it should say: "2", and if i click a third time it should say again 1. I do not have any answer, so can you please make an example script? Thanks in advance, and sorry for my bad english, i am german

  • Moderators
Posted

ManneMoses,

One way of doing it:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

$hGUI = GUICreate("Test", 500, 500)

$cButton = GUICtrlCreateButton("State 1", 10, 10, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton

            Switch GUICtrlRead($cButton)
                Case "State 1"
                    MsgBox($MB_SYSTEMMODAL, "Pressed", "State = 1")
                    GUICtrlSetData($cButton, "State 2")
                Case Else
                    MsgBox($MB_SYSTEMMODAL, "Pressed", "State = 2")
                    GUICtrlSetData($cButton, "State 1")
            EndSwitch

    EndSwitch



WEnd

Please ask if you have any questions.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted
  On 6/16/2015 at 4:05 PM, Melba23 said:

ManneMoses,

One way of doing it:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

$hGUI = GUICreate("Test", 500, 500)

$cButton = GUICtrlCreateButton("State 1", 10, 10, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton

            Switch GUICtrlRead($cButton)
                Case "State 1"
                    MsgBox($MB_SYSTEMMODAL, "Pressed", "State = 1")
                    GUICtrlSetData($cButton, "State 2")
                Case Else
                    MsgBox($MB_SYSTEMMODAL, "Pressed", "State = 2")
                    GUICtrlSetData($cButton, "State 1")
            EndSwitch

    EndSwitch



WEnd

Please ask if you have any questions.

M23

​Thank you for your quick reply, it works perfectly. But is there a way to do it without changing the buttons name? :)

  • Moderators
Posted

ManneMoses,

Sure:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

$iState = 1

$hGUI = GUICreate("Test", 500, 500)

$cButton = GUICtrlCreateButton("Press Me!", 10, 10, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton

            Switch $iState

                Case 1
                    MsgBox($MB_SYSTEMMODAL, "Pressed", "State = 1")
                    $iState = 2
                Case Else
                    MsgBox($MB_SYSTEMMODAL, "Pressed", "State = 2")
                    $iState = 1
            EndSwitch

    EndSwitch



WEnd

M23

P.S.

When you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - I know what I wrote and it just pads the thread unnecessarily.

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted (edited)

Thanks Melba23, it works, problem solved. And sorry for my quote, i do not ask questions in the forum so often

Edited by ManneMoses

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
×
×
  • Create New...