none
What does "Narrowing between implicit type conversions" mean? RRS feed

  • Question

  • I have a working program that displays a collection of icons which you can MouseOver to display a "magnified" (larger) copy.

    I ran into an issue where the compiled version of program sometimes crashes but when executed from the VS Debugger, runs just fine. So I added Option Strict On & Option Explicit On to see if sloppy code was the cause. Doing so reavealed the following "error":

    For intCnt = 0 To thumbnails.Count - 1  ' Add MouseOver support.
       Me.Controls.Add(thumbnails(intCnt))
        AddHandler _ thumbnails(intCnt).MouseHover, _
         AddressOf Thumbnails_MouseHover
        AddHandler thumbnails(intCnt).MouseLeave, _
         AddressOf Thumbnails_MouseLeave ' <-- ERROR: Option Strict On does not allow
         ' narrowing in implicit type conversions between
         ' method 'Private Sub Thumbnails_MouseLeave()' and delegate 'Delegate Sub
         ' EventHandler(sender As Object, e As EventArgs)'.
    Next

    .
    Why does "MouseHover" work but not "MouseLeave"? (If I swap the lines, the error sticks with that line so I know it's not just because it came second.)

    I'm not sure how to fix this. Any ideas? Thx.

    ADDENDUM: "thumbnails()" is of type "PictureBox".

    Thursday, August 15, 2019 3:11 PM

Answers

  • Okay, I found my mistake (I'll leave this question for future reference.)

    My "Private Sub Thumbnails_MouseLeave()" function did not contain any parameters. The fix:

    "Private Sub Thumbnails_MouseLeave(sender As Object, e As EventArgs)".

    Thursday, August 15, 2019 3:29 PM