It's more or less like this:
Protected Overrides Sub OnDiagramMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
If e.Button = Windows.Forms.MouseButtons.Middle Then
' remember the necessary values
m_CanDragDiagram = True
m_MouseDownPosition = e.Location
m_MouseDownAutoScroll = AutoScrollPosition
Me.Cursor = Cursors.SizeAll
End If
MyBase.OnDiagramMouseDown(e)
End Sub
Protected Overrides Sub OnDiagramMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
If e.Button = Windows.Forms.MouseButtons.Middle Then
m_CanDragDiagram = False
Cursor = Cursors.Default
End If
MyBase.OnDiagramMouseUp(e)
End Sub
Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
If m_CanDragDiagram Then
' difference between current mouse position and the position where the mouse was down
Dim diff As Point = Point.Subtract(m_MouseDownPosition, New Size(e.Location))
AutoScrollPosition = New Point(-m_MouseDownAutoScroll.X + diff.X, -m_MouseDownAutoScroll.Y + diff.Y)
End If
MyBase.OnMouseMove(e)
End Sub
When I scroll using scrollbars I do not get the same effect, so it's probably something wrong in my code. I've also attached a debug information to Render class and it seems to be called only a few times when I'm scrolling (sometimes only once).