Jump to content

When a button is pressed a function starts


Recommended Posts

I have been looking around and i just cant figure out how to make a function run when a button is pushed. Can someone please help me?

Hi Person2334,

The helpfile has a lot of good info on GUI creation. Here's an example of what you're talking about:

#include <ButtonConstants.au3>   ;included by Koda for GUI
#include <GUIConstantsEx.au3>   ;included by Koda for GUI
#include <WindowsConstants.au3>   ;included by Koda for GUI
Opt("GUIOnEventMode", 1)    ;set to on event mode
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 247, 113, 192, 124)  ;create GUI
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")    ;set event for user clicking red X
$btn_ClickMe = GUICtrlCreateButton("Click Me", 8, 16, 185, 57) ;create the button
GUICtrlSetOnEvent(-1, "Button1Click")      ;set event for clicking the button
GUISetState(@SW_SHOW)          ;show GUI
#EndRegion ### END Koda GUI section ###
While 1
Sleep(100)           ;loop around waiting for event
WEnd
Func Button1Click()         ;function called if button clicked see line 11
msgbox(1,"BUTTON CLICKED", "You clicked the click me button")
EndFunc
Func Form1Close()
Exit
EndFunc
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...