Jump to content

onEvent not working when button is pushed but exit works


Go to solution Solved by FireFox,

Recommended Posts

Hi all,

What I am trying to do at the moment is I have a gui and in the gui is a button, when the button is pressed it should close the gui, I haven't been able to figure out why this isn't working but it does close the gui when the x is pushed or esc so that on event is working, am I missing something?

The following code is where the button and on event is done

; ===================================== ;
;   The GUI Window Is Created Here      ;
;     Created By: Adam Blackburn        ;
; ===================================== ;

; Includes
#include <GUIConstantsEX.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIButton.au3>
#include "Conditionals.au3"

; Enable onEvent Mode
Opt("GUIOnEventMode", 1)

; GUI Windows Dimensions
Global $GUIWidth = 600
Global $GUIHeight = 400
Global $newButton

Func mainGUI()
    ; Creates the main GUI window
    $mainGUI = GUICreate("", $GUIWidth, $GUIHeight, Default, Default, BitOR($WS_CAPTION, $WS_MINIMIZEBOX, $WS_SYSMENU))

    ; Creates the "Left Pane" in the GUI Window
    $leftPane = GUICtrlCreateGroup("", 0, 10, 400, 400)
    newButton()

    ; Creates the "Right Pane" in the GUI Window
    $rightPane = GUICtrlCreateGroup("", 400, 10, 200, 400)

    ; onEvents() has all setOnEvents [ex: For when a button is pushed)
    onEvents()

    ; Show the GUI
    GUISetState(@SW_SHOW)

    ; This is so the GUI stays Open
    While 1
        Sleep(1000)
    WEnd
EndFunc   ;==>mainGUI

Func newButton()
    $newButton = GUICtrlCreateButton("New Button", 10, 10, 100, 100)
EndFunc

; All the events to do when an action is performed (button push)
Func onEvents()
    ; Exits when the button is pushed
    GUISetOnEvent($newButton, "OnExit")

    ; Close the GUI when an exit action is performed (Clicking the 'X' or 'Close' Button)
    GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit")
EndFunc   ;==>onEvents

And this is where the "exit" event is.

; ===================================== ;
;    All Conditionals are made here     ;
;   These are what to do "on event"     ;
;     Created By: Adam Blackburn        ;
; ===================================== ;

Func OnExit()
    Exit
EndFunc   ;==>OnExit
Edited by adamb53
Link to comment
Share on other sites

  • Solution

Hi,

You are using the GUISetOnEvent function for a control, however this function is only to set an event on the GUI.

Thus you need the GUICtrlSetOnEvent function, don't forget to take a look at the helpfile, it would have avoided this kind of mistake.

Br, FireFox.

Link to comment
Share on other sites

I definitely feel like an idiot now as I have done this in the past which is why I was going crazy trying to figure it out. I usually try help files first but I completely forgot about the difference between setting to the gui and to gui ctrl

Thanks for the quick response though

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...