Neutron.ahk icon indicating copy to clipboard operation
Neutron.ahk copied to clipboard

Unable to destroy gui on <MyGui>Escape

Open oyhel opened this issue 3 years ago • 2 comments

I am fairly certain the syntax for destroying the gui on the press of the escape key is correct here, but it does not work. The form is properly destroyed when pressing the close button top right. Am I missing something here or is this a bug?

; Include the Neutron library
#Include ./libs/Neutron.ahk

MADRS(){
    
    ; Create a new NeutronWindow
    Madrs := new NeutronWindow()
    Madrs.Load("madrs-neutron.html")
    Madrs.Gui("+LabelNeutron")

    ; Show the GUI
    Madrs.Show("w1200 h1200 x2500 y500")

    ; Set focus to the form
    Madrs.doc.focus()
    WinActivate, % "madrs-neutron.ahk" Madrs.hWnd
    return
    
    MadrsEscape:
        MsgBox, "escape pressed" ;this does not show
        Madrs.Destroy()  ;this does not destroy the gui
        Return

    MadrsClose:
        Madrs.Destroy()
        Return
}

Huge thanks for your work!!

oyhel avatar Sep 18 '21 17:09 oyhel

The form is properly destroyed when pressing the close button top right

That's because the close button is calling the neutron.Close() function which is set as its onclick in the examples.

This should fix it :D

; Include the Neutron library
#Include ./libs/Neutron.ahk

MADRS(){
    
    ; Create a new NeutronWindow
    global Madrs := new NeutronWindow() ; <---- the window object should be global, if you want to access it in the labels
    Madrs.Load("madrs-neutron.html")
    ; Madrs.Gui("+LabelNeutron")  ; <---- this should match the prefix you're using in the 'Close' and 'Escape' labels
    Madrs.Gui("+LabelMadrs") ; like this

    ; Show the GUI
    Madrs.Show("w1200 h1200 x2500 y500")

    ; Set focus to the form
    Madrs.doc.focus()
    WinActivate, % "madrs-neutron.ahk" Madrs.hWnd
    return
    
    MadrsEscape:
        MsgBox, "escape pressed" ;this does not show
        Madrs.Destroy()  ;this does not destroy the gui
        Return

    MadrsClose:
        Madrs.Destroy()
        Return
}

SaifAqqad avatar Sep 18 '21 18:09 SaifAqqad

Sorry for the late response, this works! Many thanks again! :D

oyhel avatar Sep 27 '21 13:09 oyhel