Class DragSelectingTool

GoDiagram®
v10.0.8
by Northwoods Software®

The DragSelectingTool lets the user select multiple parts within a rectangular area drawn by the user.

Inheritance
DragSelectingTool
Namespace: Northwoods.Go.Tools
Assembly: Northwoods.GoDiagram.WinForms.dll
Syntax
public class DragSelectingTool : Tool
Remarks

There is a temporary part, the Box, that shows the current area encompassed between the mouse-down point and the current mouse point. The default drag selection box is a magenta rectangle. You can change the Box to customize its appearance -- see its documentation for an example.

This tool is a standard mouse-move tool, the DragSelectingTool. However this cannot start running unless there has been a motionless delay after the mouse-down event of at least Delay.

This tool does not utilize any Adornments or tool handles, but it does temporarily add the Box part to the diagram. This tool does not modify the model or conduct any transaction.

Selection occurs on a mouse-up when it calls SelectInRect(Rect) with the value of ComputeBoxBounds(). Selectable parts are selected when their bounds fall entirely within the rectangle, unless IsPartialInclusion is set to true.

For customizing the DragSelectingTool, see Introduction to the DragSelectingTool.

If you implement your own drag-in-the-background-to-do-something tool, you may need to disable this tool or insert your new tool in the MouseMoveTools list before this tool, in order for your tool to run. There are examples of such tools defined in the extensions directory: Realtime Drag Selecting Tool, Drag Creating Tool, and Drag Zooming Tool.

If you want to programmatically select some Parts in a rectangular area, you can call SelectInRect(Rect).

Constructors

DragSelectingTool()

You do not normally need to create an instance of this tool because one already exists as the DragSelectingTool, which you can modify.

The Name of this tool is "DragSelecting".

Declaration
public DragSelectingTool()

Properties

Box

Gets or sets the Part used as the "rubber-band selection box" that is stretched to follow the mouse, as feedback for what area will be passed to SelectInRect(Rect) upon a mouse-up.

Declaration
public Part Box { get; set; }
Property Value
Type Description
Part
Remarks

Initially this is a Part containing only a simple magenta rectangular Shape. The object to be resized during dragging should be named "SHAPE". Setting this property does not raise any events.

Here is an example of changing the selection box to be a thicker bright green rectangle:

myDiagram.ToolManager.DragSelectingTool.Box =
  new Part { LayerName = "Tool", Selectable = false }
    .Add(new Shape { Name = "SHAPE", Fill = null, Stroke = "chartreuse", StrokeWidth = 3 });

Note that the Part should be put into a Layer that IsTemporary.

Modifying this property while this tool IsActive might have no effect.

Delay

Gets or sets the TimeSpan for which the mouse must be stationary before this tool can be started.

Declaration
public TimeSpan Delay { get; set; }
Property Value
Type Description
TimeSpan
Remarks

The default value is 175 milliseconds. Setting this property does not raise any events.

IsPartialInclusion

Gets or sets whether a selectable Part may be only partly or must be completely enclosed by the rectangle given to SelectInRect(Rect).

Declaration
public bool IsPartialInclusion { get; set; }
Property Value
Type Description
bool
Remarks

The default value is false: parts must be completely inside the rectangle. Setting this property does not raise any events.

Methods

CanStart()

This tool can run when the diagram allows selection, there has been delay of at least Delay milliseconds after the mouse-down before a mouse-move, there has been a mouse-drag far enough away not to be a click, and there is no selectable part at the mouse-down point.

Declaration
public override bool CanStart()
Returns
Type Description
bool
Overrides
Remarks

The delay required to start this tool enables both this tool and the PanningTool to co-exist as mode-less mouse-move tools.

This method may be overridden. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

ComputeBoxBounds()

This just returns a Rect stretching from the mouse-down point to the current mouse point.

Declaration
public virtual Rect ComputeBoxBounds()
Returns
Type Description
Rect

a Rect in document coordinates.

Remarks

This method may be overridden. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

DoActivate()

Capture the mouse and show the Box.

Declaration
public override void DoActivate()
Overrides

DoDeactivate()

Release the mouse and remove any Box.

Declaration
public override void DoDeactivate()
Overrides

DoMouseMove()

Update the Box's position and size according to the value of ComputeBoxBounds().

Declaration
public override void DoMouseMove()
Overrides

DoMouseUp()

Call SelectInRect(Rect) with the value of a call to ComputeBoxBounds().

Declaration
public override void DoMouseUp()
Overrides
Remarks

This method changes the cursor to "wait" and raises the "ChangingSelection" DiagramEvent before calling SelectInRect(Rect), and raises the "ChangedSelection" DiagramEvent afterward.

SelectInRect(Rect)

This method is called to select some parts within the area of a given rectangle.

Declaration
public virtual void SelectInRect(Rect r)
Parameters
Type Name Description
Rect r

a rectangular bounds in document coordinates.

Remarks

The normal behavior is to set the diagram's selection collection to only those parts in the given rectangle according to the IsPartialInclusion policy. However, if the Shift key modifier is used, no parts are deselected -- this adds to the selection the parts in the rectangle not already selected. If the Control key (Command on Mac) modifier is used, this toggles the selectedness of the parts in the rectangle. If the Control key (Command on Mac) and Shift key modifiers are both used, this deselects the parts in the rectangle.

This method may be overridden. Please read the Introduction page on Extensions for how to override methods and how to call this base method.