Class DragCreatingTool
- Namespace
- Northwoods.Go.Tools.Extensions
- Assembly
- DragCreatingWinForms.dll
The DragCreatingTool lets the user create a new node by dragging in the background to indicate its size and position.
public class DragCreatingTool : Tool
- Inheritance
-
DragCreatingTool
- Inherited Members
Remarks
The default drag selection box is a magenta rectangle. You can modify the Box to customize its appearance.
This tool will not be able to start running unless you have set the ArchetypeNodeData property to an object that can be copied and added to the diagram's model.
You can use this tool in a modal manner by executing:
diagram.CurrentTool = new DragCreatingTool();
Use this tool in a mode-less manner by executing:
myDiagram.ToolManager.MouseMoveTools.InsertAt(2, new DragCreatingTool());
However when used mode-lessly as a mouse-move tool, in MouseMoveTools, this cannot start running unless there has been a motionless delay after the mouse-down event of at least Delay milliseconds.
This tool does not utilize any Adornments or tool handles, but it does temporarily add the Box Part to the diagram. This tool does conduct a transaction when inserting the new node.
Constructors
DragCreatingTool()
Constructs a DragCreatingTool, sets Box to a magenta rectangle, and sets name of the tool.
public DragCreatingTool()
Properties
ArchetypeNodeData
Gets or sets a data object that will be copied and added to the diagram's model each time this tool executes.
public object ArchetypeNodeData { get; set; }
Property Value
Remarks
The default value is null. The value must be non-null for this tool to be able to run. Setting this property does not raise any events.
Box
Gets or sets the Part used as the "rubber-band box" that is stretched to follow the mouse, as feedback for what area will be passed to InsertPart(Rect) upon a mouse-up.
public Part Box { get; set; }
Property Value
Remarks
Initially this is a Part containing only a simple magenta rectangular Shape. The object to be resized should be named "SHAPE". Setting this property does not raise any events.
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.
public TimeSpan Delay { get; set; }
Property Value
Remarks
The default value is 175 milliseconds. A value of zero will allow this tool to run without any wait after the mouse down. Setting this property does not raise any events.
Methods
CanStart()
This tool can run when there has been a mouse-drag, far enough away not to be a click, and there has been delay of at least Delay milliseconds after the mouse-down before a mouse-move.
public override bool CanStart()
Returns
ComputeBoxBounds()
This just returns a Rect stretching from the mouse-down point to the current mouse point.
public Rect ComputeBoxBounds()
Returns
DoActivate()
Capture the mouse and show the Box.
public override void DoActivate()
DoDeactivate()
Release the mouse and remove any Box.
public override void DoDeactivate()
DoMouseMove()
Update the Box"s position and size according to the value of ComputeBoxBounds().
public override void DoMouseMove()
DoMouseUp()
Call InsertPart(Rect) with the value of a call to ComputeBoxBounds().
public override void DoMouseUp()
InsertPart(Rect)
Create a node by adding a copy of the ArchetypeNodeData object to the diagram's model, assign its Position and DesiredSize according to the given bounds, and select the new part.
public virtual Part InsertPart(Rect bounds)
Parameters
bounds
Recta Point in document coordinates.
Returns
- Part
the newly created Part, or null if it failed.
Remarks
The actual part that is added to the diagram may be a Part, a Node, or even a Group, depending on the properties of the ArchetypeNodeData and the type of the template that is copied to create the part.