Jump to content

Assign a function to a button


Go to solution Solved by FireFox,

Recommended Posts

Posted

Hi. 

I used search function and readed so much topics but i didn't understand yet how to assing a function to a GUIed button.

I didn't understand how that Switch and Select work.

Could someone make me an example assigning a function to a button ?

Posted (edited)

It's a Switch statement you need, not a Select.

Switch $iMsg
    Case $Button1
        ...


;Or (but not recommended)
Select
    Case $iMsg = $Button1
        ...

_

Br, FireFox.

Edited by FireFox
Posted

Switch $iMsg

There's a variable to compare with Case statements.

Take a look at the helpfile you will find all informations you need, it seems like you're not applying carrefuly the examples.

Br, FireFox.

Posted

It's not that i didn't apply it,it's that i didn't understand what to do with them 

I used also that variable but i didn't work neither

What about making a pratic example? Something stupid just like showing up a msgbox after pressing a button

And about the help file, in my personal mind i think that the 60% of the examples there are just confusing for newbies like me.

  • Solution
Posted

There are examples everywhere, even in the helpfile. I don't get it.

Anyway :

#include <GUIConstantsEx.au3>

GUICreate("MyGUI")

$iButton1 = GUICtrlCreateButton("Button1", 20, 20, 80, 22)

GUISetState(@SW_SHOW)

Local $iMsg = 0

While 1
    $iMsg = GUIGetMsg()

    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $iButton1
            MsgBox(0, "", "Button1 clicked")
    EndSwitch
WEnd

Br, FireFox.

Posted
First you draw a GUIDE ago by koda 
 
 
Then we will handle: D 
 
A simple example
 
#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode",1) ; Enable GUI Event Mode with 1
; Start Create GUI
$hGUI = GUICreate("Example",500,500,-1,-1)
$But = GUICtrlCreateButton("Click",100,100,100,100)
GUISetState() ; Show GUI
;Set Event Click
GUISetOnEvent($GUI_EVENT_CLOSE,"Exit1") ; If you press the X button ---> Call Function Exit1
GUICtrlSetOnEvent($But,"Notepad") ; If Click to Button ---> Call Function Note

Func Notepad()
    Run("notepad.exe")
EndFunc

Func Exit1()
    Exit
EndFunc

; mandatory
While 1
    Sleep(10)
WEnd

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
  • Recently Browsing   0 members

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