Jump to content

Button with 2 Functions


Recommended Posts

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

Link to comment
Share on other sites

  • Moderators

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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? :)

Link to comment
Share on other sites

  • Moderators

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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

×
×
  • Create New...