Example #1
0
        // Be sure to call the base class constructor.
        public EditionAdorner(UIElement adornedElement, CustomStroke stroke, CustomInkCanvas canvas)
            : base(adornedElement)
        {
            adornedStroke = stroke;

            this.stroke = stroke;
            this.canvas = canvas;

            Point center = stroke.GetCenter();

            if (stroke is ShapeStroke)
            {
                rotationDelete = new RotateTransform((stroke as ShapeStroke).shapeStyle.rotation,
                                                     -20 - (stroke as ShapeStroke).shapeStyle.width / 2, 20 + (stroke as ShapeStroke).shapeStyle.height / 2);
            }
            else
            {
                rotationDelete = new RotateTransform(0, 0, 0);
            }

            if (stroke is ShapeStroke)
            {
                rotationEdit = new RotateTransform((stroke as ShapeStroke).shapeStyle.rotation,
                                                   -(stroke as ShapeStroke).shapeStyle.width / 2, 20 + (stroke as ShapeStroke).shapeStyle.height / 2);
            }
            else
            {
                rotationEdit = new RotateTransform(0, 0, 0);
            }

            rectangleEdit   = new Rect(stroke.GetCustomBound().TopRight.X, stroke.GetCustomBound().TopRight.Y - 20, 20, 20);
            rectangleDelete = new Rect(stroke.GetCustomBound().TopRight.X + 20, stroke.GetCustomBound().TopRight.Y - 20, 20, 20);

            AddButtons(stroke, canvas);
        }
        public AnchorPointAdorner(UIElement adornedElement, CustomStroke customStroke, CustomInkCanvas actualCanvas)
            : base(adornedElement)
        {
            adornedStroke = customStroke;

            visualChildren = new VisualCollection(this);

            linkPreview                 = new Path();
            linkPreview.Stroke          = Brushes.Gray;
            linkPreview.StrokeThickness = 2;
            visualChildren.Add(linkPreview);

            shapeStroke = customStroke as ShapeStroke;
            canvas      = actualCanvas;
            // rotation initiale de la stroke (pour dessiner le rectangle)
            // Bug. Cheat, but the geometry, the selection Rectangle (newRect) should be the right one.. geom of the stroke?
            strokeBounds = customStroke.GetCustomBound();
            Point center = customStroke.GetCenter();

            rotation = new RotateTransform((customStroke as ShapeStroke).shapeStyle.rotation, center.X, center.Y);

            anchors = new List <Thumb>();
            anchors.Add(new Thumb());
            anchors.Add(new Thumb());
            anchors.Add(new Thumb());
            anchors.Add(new Thumb());

            foreach (Thumb anchor in anchors)
            {
                anchor.Cursor          = Cursors.ScrollAll;
                anchor.Width           = 6;
                anchor.Height          = 6;
                anchor.Background      = Brushes.DodgerBlue;
                anchor.BorderBrush     = Brushes.Black;
                anchor.BorderThickness = new Thickness(2);
                anchor.Margin          = new Thickness(0);

                anchor.DragStarted   += new DragStartedEventHandler(dragHandle_DragStarted);
                anchor.DragDelta     += new DragDeltaEventHandler(dragHandle_DragDelta);
                anchor.DragCompleted += new DragCompletedEventHandler(dragHandle_DragCompleted);

                visualChildren.Add(anchor);
            }

            cheatAnchors = new List <StrokeAnchorPointThumb>();
            cheatAnchors.Add(new StrokeAnchorPointThumb(shapeStroke, canvas, 0));
            cheatAnchors.Add(new StrokeAnchorPointThumb(shapeStroke, canvas, 1));
            cheatAnchors.Add(new StrokeAnchorPointThumb(shapeStroke, canvas, 2));
            cheatAnchors.Add(new StrokeAnchorPointThumb(shapeStroke, canvas, 3));
            foreach (Thumb cheatAnchor in cheatAnchors)
            {
                cheatAnchor.Cursor = Cursors.SizeNWSE;
                cheatAnchor.Width  = 1;
                cheatAnchor.Height = 1;

                canvas.Children.Add(cheatAnchor);
            }

            strokeBounds = customStroke.GetCustomBound();
        }
        // Be sure to call the base class constructor.
        public RemoteSelectionAdorner(UIElement adornedElement, CustomStroke stroke, CustomInkCanvas canvas)
            : base(adornedElement)
        {
            adornedStroke = stroke;

            this.stroke    = stroke;
            this.canvas    = canvas;
            visualChildren = new VisualCollection(this);

            border = new Path();
            if (stroke is ShapeStroke)
            {
                Point           center   = stroke.GetCenter();
                RotateTransform rotation = new RotateTransform((stroke as ShapeStroke).shapeStyle.rotation, center.X, center.Y);

                fill                   = new RectangleGeometry(stroke.GetCustomBound(), 0, 0, rotation);
                border.Data            = fill;
                border.StrokeThickness = 2;
            }
            else
            {
                border.Data            = stroke.GetGeometry();
                border.StrokeThickness = (stroke as LinkStroke).getThickness();
            }

            border.Stroke = (Brush) new BrushConverter().ConvertFromString("#CC7F7F");

            visualChildren.Add(border);
        }
        /// <summary>
        /// Draw the rotation handle and the outline of
        /// the element.
        /// </summary>
        /// <param name="finalSize">The final area within the
        /// parent that this element should use to arrange
        /// itself and its children.</param>
        /// <returns>The actual size used. </returns>
        protected override Size ArrangeOverride(Size finalSize)
        {
            if (stroke.GetCustomBound().IsEmpty)
            {
                return(finalSize);
            }

            border.Arrange(new Rect(new Size(canvas.ActualWidth, canvas.ActualHeight)));
            return(finalSize);
        }
        public RotateAdorner(UIElement adornedElement, CustomStroke strokeToRotate, CustomInkCanvas actualCanvas)
            : base(adornedElement)
        {
            adornedStroke = strokeToRotate;
            stroke        = strokeToRotate;
            canvas        = actualCanvas;
            // rotation initiale de la stroke (pour dessiner le rectangle)
            // Bug. Cheat, but the geometry, the selection Rectangle (newRect) should be the right one.. geom of the stroke?
            strokeBounds = strokeToRotate.GetCustomBound();
            center       = stroke.GetCenter();
            rotation     = new RotateTransform((stroke as ShapeStroke).shapeStyle.rotation, center.X, center.Y);

            visualChildren = new VisualCollection(this);

            line                 = new Path();
            line.Stroke          = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF809dce"));
            line.StrokeThickness = 1;

            line.Data = new LineGeometry(new Point(center.X, center.Y - strokeBounds.Height / 2 - 10),
                                         new Point(center.X, center.Y - strokeBounds.Height / 2 - HANDLEMARGIN));
            line.RenderTransform = rotation;

            visualChildren.Add(line);

            rotateHandle            = new Thumb();
            rotateHandle.Cursor     = Cursors.Hand;
            rotateHandle.Width      = 10;
            rotateHandle.Height     = 10;
            rotateHandle.Background = new LinearGradientBrush((Color)ColorConverter.ConvertFromString("#FFc8d4ea"),
                                                              (Color)ColorConverter.ConvertFromString("#FF809dce"), 45);

            rotateHandle.DragDelta     += new DragDeltaEventHandler(rotateHandle_DragDelta);
            rotateHandle.DragCompleted += new DragCompletedEventHandler(rotateHandle_DragCompleted);

            TransformGroup transform = new TransformGroup();

            transform.Children.Add(new RotateTransform(rotation.Angle,
                                                       rotateHandle.Width / 2,
                                                       rotateHandle.Height / 2 + HANDLEMARGIN + stroke.GetCustomBound().Height / 2));
            transform.Children.Add(new TranslateTransform(-canvas.ActualWidth / 2 + strokeBounds.X + strokeBounds.Width / 2,
                                                          -canvas.ActualHeight / 2 + strokeBounds.Y - HANDLEMARGIN));

            rotateHandle.RenderTransform = transform;

            visualChildren.Add(rotateHandle);

            rotatePreview                 = new Path();
            rotatePreview.Stroke          = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFBBBBBB"));
            rotatePreview.StrokeThickness = 1;
            visualChildren.Add(rotatePreview);
        }
        /// <summary>
        /// Rotates the rectangle representing the
        /// strokes' bounds as the user drags the
        /// Thumb.
        /// </summary>
        void rotateHandle_DragDelta(object sender, DragDeltaEventArgs e)
        {
            // Find the angle of which to rotate the shape.  Use the right
            // triangle that uses the center and the mouse's position
            // as vertices for the hypotenuse.

            Point pos = Mouse.GetPosition(this);

            double deltaX = pos.X - center.X;
            double deltaY = pos.Y - center.Y;

            if (deltaY.Equals(0))
            {
                return;
            }

            double tan   = deltaX / deltaY;
            double angle = Math.Atan(tan);

            // Convert to degrees.
            angle = angle * 180 / Math.PI;

            // If the mouse crosses the vertical center,
            // find the complementary angle.
            if (deltaY > 0)
            {
                angle = 180 - Math.Abs(angle);
            }

            // Rotate left if the mouse moves left and right
            // if the mouse moves right.
            if (deltaX < 0)
            {
                angle = -Math.Abs(angle);
            }
            else
            {
                angle = Math.Abs(angle);
            }

            if (Double.IsNaN(angle))
            {
                return;
            }

            // Apply the rotation to the strokes' outline.
            rotation = new RotateTransform(angle, center.X, center.Y);

            NewRectangle       = new RectangleGeometry(stroke.GetCustomBound(), 0, 0, rotation);
            rotatePreview.Data = NewRectangle;
            rotatePreview.Arrange(new Rect(new Size(canvas.ActualWidth, canvas.ActualHeight)));

            line.RenderTransform = rotation;

            TransformGroup transform = new TransformGroup();

            transform.Children.Add(new RotateTransform(rotation.Angle,
                                                       rotateHandle.Width / 2,
                                                       rotateHandle.Height / 2 + HANDLEMARGIN + stroke.GetCustomBound().Height / 2));
            transform.Children.Add(new TranslateTransform(-canvas.ActualWidth / 2 + strokeBounds.X + strokeBounds.Width / 2,
                                                          -canvas.ActualHeight / 2 + strokeBounds.Y - HANDLEMARGIN));

            rotateHandle.RenderTransform = transform;
        }
Example #7
0
        void All_DragStarted(object sender, DragStartedEventArgs e)
        {
            Rect rectangle = new Rect(customStroke.GetCustomBound().X,
                                      customStroke.GetCustomBound().Y,
                                      customStroke.GetCustomBound().Width,
                                      customStroke.GetCustomBound().Height);

            OldRectangle = new RectangleGeometry(rectangle, 0, 0, rotation);
        }
Example #8
0
        public ResizeAdorner(UIElement adornedElement, CustomStroke customStroke, CustomInkCanvas actualCanvas)
            : base(adornedElement)
        {
            if (customStroke is LinkStroke)
            {
                WIDTH_LEGER = 1;
            }
            adornedStroke = customStroke;

            visualChildren = new VisualCollection(this);

            if (customStroke is ShapeStroke)
            {
                strokeBounds = customStroke.GetCustomBound();
            }
            else
            {
                strokeBounds = (customStroke as LinkStroke).GetStraightBounds();
            }

            resizePreview                 = new Path();
            resizePreview.Stroke          = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFBBBBBB"));
            resizePreview.StrokeThickness = 1;
            visualChildren.Add(resizePreview);

            this.customStroke = customStroke;
            canvas            = actualCanvas;

            Point center = customStroke.GetCenter();

            if (customStroke is ShapeStroke)
            {
                rotation = new RotateTransform((customStroke as ShapeStroke).shapeStyle.rotation, center.X, center.Y);
            }
            else
            {
                rotation = new RotateTransform(0, center.X, center.Y);
            }
            while (rotation.Angle < 0)
            {
                rotation.Angle += 360;
            }

            outerBoundPath                 = new Path();
            outerBoundPath.Stroke          = Brushes.Black;
            outerBoundPath.StrokeDashArray = new DoubleCollection {
                5, 2
            };
            outerBoundPath.StrokeThickness = 1;
            Rect rect = customStroke.GetCustomBound();

            rect.X             -= MARGIN;
            rect.Y             -= MARGIN;
            rect.Width         += MARGIN * 2;
            rect.Height        += MARGIN * 2;
            outerBoundPath.Data = new RectangleGeometry(rect, 0, 0, rotation);
            visualChildren.Add(outerBoundPath);

            moveThumb                 = new Thumb();
            moveThumb.Cursor          = Cursors.SizeAll;
            moveThumb.Height          = strokeBounds.Height + MARGIN * 2;
            moveThumb.Width           = strokeBounds.Width + MARGIN * 2;
            moveThumb.Background      = Brushes.Transparent;
            moveThumb.DragDelta      += new DragDeltaEventHandler(Move_DragDelta);
            moveThumb.DragCompleted  += new DragCompletedEventHandler(Move_DragCompleted);
            moveThumb.DragStarted    += new DragStartedEventHandler(All_DragStarted);
            moveThumb.PreviewMouseUp += new MouseButtonEventHandler(LeftMouseUp);
            TransformGroup transform = new TransformGroup();

            transform.Children.Add(new RotateTransform(rotation.Angle, moveThumb.Width / 2, moveThumb.Height / 2));
            transform.Children.Add(new TranslateTransform(-canvas.ActualWidth / 2 + strokeBounds.Width / 2 + strokeBounds.X,
                                                          -canvas.ActualHeight / 2 + strokeBounds.Height / 2 + strokeBounds.Y));
            moveThumb.RenderTransform = transform;


            visualChildren.Add(moveThumb);

            unitX = rotation.Value.Transform(unitX);
            unitY = rotation.Value.Transform(unitY);
            // RenderTransform = rotation;

            anchors = new List <Thumb>();
            anchors.Add(new Thumb());
            anchors.Add(new Thumb());
            anchors.Add(new Thumb());
            anchors.Add(new Thumb());
            anchors.Add(new Thumb());
            anchors.Add(new Thumb());
            anchors.Add(new Thumb());
            anchors.Add(new Thumb());

            int index = 0;

            foreach (Thumb anchor in anchors)
            {
                anchor.Width      = 8;
                anchor.Height     = 8;
                anchor.Background = new LinearGradientBrush((Color)ColorConverter.ConvertFromString("#FFc8d4ea"),
                                                            (Color)ColorConverter.ConvertFromString("#FF809dce"), 45);
                anchor.BorderBrush = Brushes.Black;
                if (rotation.Angle % 360 >= 360 - 45 / 2 || rotation.Angle % 360 <= 45 / 2)
                {
                    switch (index)
                    {
                    case 0:
                        anchor.DragDelta += new DragDeltaEventHandler(Top_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 1:
                        anchor.DragDelta += new DragDeltaEventHandler(Right_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 2:
                        anchor.DragDelta += new DragDeltaEventHandler(Bottom_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 3:
                        anchor.DragDelta += new DragDeltaEventHandler(Left_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 4:
                        anchor.DragDelta += new DragDeltaEventHandler(TopLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 5:
                        anchor.DragDelta += new DragDeltaEventHandler(TopRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 6:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 7:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    default:
                        break;
                    }
                }
                else if (rotation.Angle % 360 > 45 / 2 && rotation.Angle % 360 <= 90 - 45 / 2)
                {
                    switch (index)
                    {
                    case 0:
                        anchor.DragDelta += new DragDeltaEventHandler(Top_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 1:
                        anchor.DragDelta += new DragDeltaEventHandler(Right_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 2:
                        anchor.DragDelta += new DragDeltaEventHandler(Bottom_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 3:
                        anchor.DragDelta += new DragDeltaEventHandler(Left_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 4:
                        anchor.DragDelta += new DragDeltaEventHandler(TopLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 5:
                        anchor.DragDelta += new DragDeltaEventHandler(TopRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 6:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 7:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    default:
                        break;
                    }
                }
                else if (rotation.Angle % 360 > 90 - 45 / 2 && rotation.Angle % 360 <= 90 + 45 / 2)
                {
                    switch (index)
                    {
                    case 0:
                        anchor.DragDelta += new DragDeltaEventHandler(Top_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 1:
                        anchor.DragDelta += new DragDeltaEventHandler(Right_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 2:
                        anchor.DragDelta += new DragDeltaEventHandler(Bottom_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 3:
                        anchor.DragDelta += new DragDeltaEventHandler(Left_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 4:
                        anchor.DragDelta += new DragDeltaEventHandler(TopLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 5:
                        anchor.DragDelta += new DragDeltaEventHandler(TopRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 6:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 7:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    default:
                        break;
                    }
                }
                else if (rotation.Angle % 360 > 90 + 45 / 2 && rotation.Angle % 360 <= 135 + 45 / 2)
                {
                    switch (index)
                    {
                    case 0:
                        anchor.DragDelta += new DragDeltaEventHandler(Top_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 1:
                        anchor.DragDelta += new DragDeltaEventHandler(Right_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 2:
                        anchor.DragDelta += new DragDeltaEventHandler(Bottom_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 3:
                        anchor.DragDelta += new DragDeltaEventHandler(Left_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 4:
                        anchor.DragDelta += new DragDeltaEventHandler(TopLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 5:
                        anchor.DragDelta += new DragDeltaEventHandler(TopRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 6:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 7:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    default:
                        break;
                    }
                }
                else if (rotation.Angle % 360 > 180 - 45 / 2 && rotation.Angle % 360 <= 180 + 45 / 2)
                {
                    switch (index)
                    {
                    case 0:
                        anchor.DragDelta += new DragDeltaEventHandler(Top_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 1:
                        anchor.DragDelta += new DragDeltaEventHandler(Right_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 2:
                        anchor.DragDelta += new DragDeltaEventHandler(Bottom_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 3:
                        anchor.DragDelta += new DragDeltaEventHandler(Left_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 4:
                        anchor.DragDelta += new DragDeltaEventHandler(TopLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 5:
                        anchor.DragDelta += new DragDeltaEventHandler(TopRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 6:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 7:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    default:
                        break;
                    }
                }
                else if (rotation.Angle % 360 > 225 - 45 / 2 && rotation.Angle % 360 <= 225 + 45 / 2)
                {
                    switch (index)
                    {
                    case 0:
                        anchor.DragDelta += new DragDeltaEventHandler(Top_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 1:
                        anchor.DragDelta += new DragDeltaEventHandler(Right_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 2:
                        anchor.DragDelta += new DragDeltaEventHandler(Bottom_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 3:
                        anchor.DragDelta += new DragDeltaEventHandler(Left_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 4:
                        anchor.DragDelta += new DragDeltaEventHandler(TopLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 5:
                        anchor.DragDelta += new DragDeltaEventHandler(TopRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 6:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 7:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    default:
                        break;
                    }
                }
                else if (rotation.Angle % 360 > 270 - 45 / 2 && rotation.Angle % 360 <= 270 + 45 / 2)
                {
                    switch (index)
                    {
                    case 0:
                        anchor.DragDelta += new DragDeltaEventHandler(Top_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 1:
                        anchor.DragDelta += new DragDeltaEventHandler(Right_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 2:
                        anchor.DragDelta += new DragDeltaEventHandler(Bottom_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 3:
                        anchor.DragDelta += new DragDeltaEventHandler(Left_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 4:
                        anchor.DragDelta += new DragDeltaEventHandler(TopLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 5:
                        anchor.DragDelta += new DragDeltaEventHandler(TopRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 6:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 7:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    switch (index)
                    {
                    case 0:
                        anchor.DragDelta += new DragDeltaEventHandler(Top_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 1:
                        anchor.DragDelta += new DragDeltaEventHandler(Right_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 2:
                        anchor.DragDelta += new DragDeltaEventHandler(Bottom_DragDelta);
                        anchor.Cursor     = Cursors.SizeNWSE;
                        break;

                    case 3:
                        anchor.DragDelta += new DragDeltaEventHandler(Left_DragDelta);
                        anchor.Cursor     = Cursors.SizeNESW;
                        break;

                    case 4:
                        anchor.DragDelta += new DragDeltaEventHandler(TopLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    case 5:
                        anchor.DragDelta += new DragDeltaEventHandler(TopRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 6:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomLeft_DragDelta);
                        anchor.Cursor     = Cursors.SizeNS;
                        break;

                    case 7:
                        anchor.DragDelta += new DragDeltaEventHandler(BottomRight_DragDelta);
                        anchor.Cursor     = Cursors.SizeWE;
                        break;

                    default:
                        break;
                    }
                }
                anchor.DragStarted   += new DragStartedEventHandler(All_DragStarted);
                anchor.DragCompleted += new DragCompletedEventHandler(All_DragCompleted);
                if (!(customStroke is LinkStroke) || !(customStroke as LinkStroke).isAttached())
                {
                    visualChildren.Add(anchor);
                }
                double xOffset = 0;
                double yOffset = 0;
                switch (index)
                {
                case 0:     //Top
                    xOffset = strokeBounds.Width / 2;
                    yOffset = -MARGIN;
                    break;

                case 1:     //Right
                    xOffset = strokeBounds.Width + MARGIN;
                    yOffset = strokeBounds.Height / 2;
                    break;

                case 2:     //Bottom
                    xOffset = strokeBounds.Width / 2;
                    yOffset = strokeBounds.Height + MARGIN;
                    break;

                case 3:     //Left
                    xOffset = -MARGIN;
                    yOffset = strokeBounds.Height / 2;
                    break;

                case 4:     //TopLeft
                    xOffset = -MARGIN;
                    yOffset = -MARGIN;
                    break;

                case 5:     //TopRight
                    xOffset = strokeBounds.Width + MARGIN;
                    yOffset = -MARGIN;
                    break;

                case 6:     //BottomLeft
                    xOffset = -MARGIN;
                    yOffset = strokeBounds.Height + MARGIN;
                    break;

                case 7:     //BottomRight
                    xOffset = strokeBounds.Width + MARGIN;
                    yOffset = strokeBounds.Height + MARGIN;
                    break;

                default:
                    break;
                }
                ArrangeAnchor(anchor, xOffset, yOffset);
                index++;
            }

            rotationPreview = rotation.Clone();
        }