LoadPicture is not working or syntax unknown

Issue #24 closed
Winter Laite created an issue

This AHK code works.

MyGui := Gui(, "KEYSHARP TESTS")
Handle := LoadPicture(A_ScriptDir "\monkey.ico")
MyGui.Add("Picture", "w30 h30 x10 y+10" , A_ScriptDir "\monkey.ico")
MyButton := MyGui.Add("Button", , "Get monkey icon handle")
MyButton.OnEvent("Click", ExposeMonkey)

MyGui.Show()

ExposeMonkey(*) {
    MsgBox(Handle)
}

Tried modifying this code to expect a Map/Dictionary:

MyGui := Gui(, "KEYSHARP TESTS")
Handle := LoadPicture(A_ScriptDir "\monkey.ico")
MyGui.Add("Picture", "w30 h30 x10 y+10" , A_ScriptDir "\monkey.ico")
MyButton := MyGui.Add("Button", , "Get monkey icon handle")
MyButton.OnEvent("Click", "ExposeMonkey")

MyGui.Show()

ExposeMonkey() {
    MsgBox(Handle["ImageType"])
}

And got this error:

Uncaught Keysharp exception:

Message: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')

Reference is to Keysharp.Core\Common\ImageHelper.cs at line 75.

Comments (6)

  1. Winter Laite reporter

    Suggested fix. Compiles and runs correctly with suggested fix. Starts at line 17 of Keysharp.Core\Core\Images.cs.

                // var width = int.MinValue;
                int width = 0;
                // var height = int.MinValue;
                int height = 0;
                // var icon = int.MinValue;
                int icon = 0;
    

    This gets rid of the negative index error.

    Keysharp code that works after fix.

    MyGui := Gui(, "KEYSHARP TESTS")
    Handle := LoadPicture(A_ScriptDir "\monkey.ico")
    MyGui.Add("Picture", "w30 h30 x10 y+10" , A_ScriptDir "\monkey.ico")
    MyButton := MyGui.Add("Button", , "Get monkey icon handle")
    MyButton.OnEvent("Click", "ExposeMonkey")
    
    MyGui.Show()
    
    ExposeMonkey() {
        MsgBox("Handle: " Handle["Handle"] "`nImageType: " Handle["ImageType"])
    }
    

  2. Log in to comment