none
Simple tip about MouseMove events returning a bad value RRS feed

  • General discussion

  • If you're using the MouseMove event of a control to derive an X or Y value that you then use as an index to an array, be sure to use Try/Catch for error trapping.

    For example: If you have a PictureBox that is 500 pixels wide, and you use the Mouse.X as an index to an array with 500 elements..

    What I have found is, that on rare occasion, a quick mouse movement out of the control will return a value beyond 500 or less than 0 that will then cause an out of range exception.

    In the four months of developing my application, and hundreds of test runs, it has happened about three times.

    Perhaps not strictly a VB.Net problem, or perhaps is already common knowledge, but I thought I'd throw it out there as something you'd think would never return bad values may actually do so.

    DW

    Thursday, August 10, 2017 2:45 PM