Search code examples
vb.netsystem.drawing

Scrollable with the mouse


I have a panning on my usercontrol that for some reason if only the X or only the Y changes it will set the them back to 0. I have it where if x = 0 or y = 0 based on the change equals zero the AutoScrollPosition automatically sets it to the same position as it was before. So if AutoScrollPosition.X = -67, I set the new position in the code to be the previous AutoScrollPosition.X.

        `AutoScrollPosition = Point.Round(New PointF(AutoScrollPosition.X, MouseChange.Y - AutoScrollPosition.Y)) `

The System.Drawing.Point.AutoScrollPosition.X becomes 0 and it shouldn't change. Does anyone know why it does this? Is this a behavior that I should expected from this class and variable?


Solution

  • Hans Passant answer

    You did it correctly for Y but not for X. You must use -AutoScrollPosition.X, note the negative sign.

    Actual answer with code is

    AutoScrollPosition = Point.Round(New PointF(-AutoScrollPosition.X, MouseChange.Y - AutoScrollPosition.Y))