Gui_Close not functioning correctly

Issue #18 closed
Winter Laite created an issue

This code works in v2.0-beta.7:

myGui := Gui()
myGui.AddText("", "Press Alt+F4 or the X button in the title bar.")
myGui.OnEvent("Close", myGui_Close)
myGui_Close(thisGui) {  ; Declaring this parameter is optional.
    if MsgBox("Are you sure you want to close the GUI?",, "y/n") = "No"
        return True  ; true = 1
}
myGui.Show()

All my attempts to get this to work in keysharp have been without success. Here is one attempt:

myGui := Gui()
myGui.AddText("", "Press Alt+F4 or the X button in the title bar.")
myGui.OnEvent("Close", "myGui_Close")
myGui_Close(thisGui) {  ; Declaring this parameter is optional.
    if (MsgBox("Are you sure you want to close the GUI?",, 4) == "No")
        return True  ; true = 1
}
myGui.Show()

My attempt solved a failure to honor “y/n” (trivial), but I’m unsure where to go next. It appears a Keysharp MsgBox with this option (Yes/No) returns a string “Yes” or a string “No.”, but I tried the following returns (and several others) without luck:

    if (MsgBox("Are you sure you want to close the GUI?",, 4) == "No")
        return("No") 
    if (MsgBox("Are you sure you want to close the GUI?",, 4) == "No")
        return(1) 

Comments (5)

  1. Winter Laite reporter

    Looking at the Keysharp code, I can fix the “y/n” issue by changing it to uppercase as well as using '4'.

  2. Matt Feemster repo owner

    Fix committed. You can use “y/n”, as you observed it was a casing issue.

    Also, the return value is properly observed to prevent closing the window when clicking no.

    Please test.

  3. Winter Laite reporter

    Tested following code, works fine, please mark resolved and closed. Thanks!

    myGui := Gui()
    myGui.AddText("", "Press Alt+F4 or the X button in the title bar.")
    myGui.OnEvent("Close", "myGui_Close")
    myGui_Close() {  
        if (MsgBox("Are you sure you want to close the GUI?",, 4) == "No")
            return True
    }
    myGui.Show()
    

  4. Log in to comment