To drag a retangle using right button?


I know the user can drag a region in GoView using Left mouse button (press and drag), but also I want to the user to do this using Right mouse button (press and drag), so that I can auto zoom into the dragged region.

So could you show me the easiest way to show the drag rect when the Right mouse button is used?


The standard behavior you are talking about is implemented by the GoToolZooming tool, but it assumes the use of the left mouse button.
So if you want to use this zooming tool in a modeless fashion, you just need to override GoToolZooming.CanStart to be true when this.FirstInput.IsContextButton is true. Then the natural thing to do is to add an instance of this tool to your GoView.MouseMoveTools list.
However, this tool won’t ever get a chance to start because the context button tool, GoToolContext, also has a CanStart method that is true when this.FirstInput.IsContextButton, and the GoToolContext tool is checked first because it is in the GoView.MouseDownTools list. So it should work if you move the GoToolContext tool to be considered after your zooming tool.
public class RightMouseZoomingTool : GoToolZooming {
public RightMouseZoomingTool(GoView view) : base(view) { }
public override bool CanStart() {
return this.FirstInput.IsContextButton; // GoToolZooming normally checks that it is NOT the right mouse button

goView1.MouseMoveTools.Add(new RightMouseZoomingTool(goView1));
IGoTool ctxttool = goView1.ReplaceMouseTool(typeof(GoToolContext), null); // remove standard context menu button tool,
goView1.MouseMoveTools.Add(ctxttool); // and add after the new RightMouseZoomingTool

Also see this topic: 1

Thanks. It works great. I used the code in your linked post to bring the context menu back.