We would like to implement a Hand tool that is similar to Acrobat
Reader (or google maps); for example, you manually grab a location in
the top right corner and drag the view toward the center.
GoToolPanning with AutoPan = false has the opposite behaviour of what
we are trying to do. Can someone suggest a workaround?
I got the desired effect by creating my own PanningTool. I included the code for your consumption
using System.Drawing;
using System.Windows.Forms;
using Northwoods.Go;
namespace DemandDS.App.MVCA.FCDiagramMVCA.Diagram
{
///
/// The PanningTool behaves like Acrobat Reader or
Google Maps. It allows the user to “grab” a location of
/// the view and move it around.
///
public class PanningTool: GoTool
{
// Initial location on the first mouse down.
private PointF Origin = new PointF(0,0);
private Cursor panDefault;
private Cursor panGrab;
/// <summary>
/// Constructor
/// </summary>
/// <param name="view"></param>
public PanningTool(GoView view) : base(view)
{
panDefault = AppResourceManager.GetCursor("PanDefault.png");
panGrab = AppResourceManager.GetCursor("PanGrab.png");
}
public override void Start()
{
base.Start ();
}
public override void Stop()
{
base.Stop ();
}
/// <summary>
/// On mouse down, grab the location and change the cursor the hand grab icon.
/// </summary>
public override void DoMouseDown()
{
Origin = new
/// <summary>
/// Reposition the view as the user moves the mouse.
/// </summary>
public override void DoMouseMove()
{
if (LastInput.MouseEventArgs.Button == MouseButtons.Left)
{
//
(_ProView.FindMouseTool(typeof(GoToolRubberBanding))
as GoToolRubberBanding).Stop();
View.DocPosition = new PointF(View.DocPosition.X -
offset.X, View.DocPosition.Y - offset.Y);
Origin = new PointF(LastInput.MouseEventArgs.X,
LastInput.MouseEventArgs .Y);
}
base.DoMouseMove ();
}
/// <summary>
/// Restores cursor on mouse up ready for the next grab and drag.
/// </summary>
public override void DoMouseUp()
{
View.Cursor = panDefault;
base.DoMouseUp ();
}
}// PanningTool
Thanks for the code, but I don’t understand why GoToolPanning with AutoPan == false doesn’t give you behavior like Google Maps or Acrobat Reader? It does when I try it:
// modal manual panning: (left mouse button)
GoToolPanning panningtool = new GoToolPanning(myView);
panningtool.AutoPan = false;
panningtool.Modal = true;
myView.Tool = panningtool;