/// <inheritdoc /> protected override void Initialize() { this.DetachHandlers(); this.pickingTool?.Dispose(); this.pickingTool = this.CreatePickingTool(this.inputRange, InputTypes.Point); this.AttachHandlers(); this.pickingTool.StartPickingSession("Pick two points."); }
protected override void OnMouseUp(MouseEventArgs args) { base.OnMouseUp(args); if (FullDragMode) { FullDragMode = false; } Point lLocation = GetScrollablePoint(args.Location); switch (args.Button) { case MouseButtons.Right: SelectedTool = HitTest(lLocation); if (SelectedTool != null) { _contextMenuStrip.Show(this, args.Location); } break; case MouseButtons.Left: // End tracker resize operation. if (SelectedTool != null && SelectedTool.Tracker.IsResizing) { Rectangle lRect = SelectedTool.SurroundingRect; int lWidth = SelectedTool.Tracker.Margin + 1; // +1 for SmoothingMode.AntiAlias InvalidateRect(InflateRect(SelectedTool.SurroundingRect, lWidth, lWidth)); SelectedTool.Tracker.EndResize(lLocation); InvalidateRect(InflateRect(SelectedTool.SurroundingRect, lWidth, lWidth)); SelectedTool = SelectedTool; // refresh property grid IsDirty = true; } else if (PickingTool != null) { if (PickingTool.EndResize(lLocation)) { AddTool(PickingTool); SelectedTool = PickingTool; InvalidateRect(PickingTool.SurroundingRect); PickingTool = null; } } break; } DragBoxFromMouseDown = Rectangle.Empty; DraggingPoint = Point.Empty; }
//private static readonly Color DesignTitleBaseColor = Color.FromArgb(50, 50, 50); //private static readonly Color DesignTitleLightingColor = Color.FromArgb(200, 200, 200); //protected int CaptionHeight { get; set; } //private void PaintTitle(PaintEventArgs args) //{ // Graphics graph = args.Graphics; // Rectangle rect = new Rectangle(Bounds.Left, Bounds.Top, AutoScrollMinSize.Width, CaptionHeight); // rect = GraphicsMapper.Instance.TransformRectangle(rect); // //if (args.Graphics.ClipBounds.IntersectsWith(rect)) // { // Brush brush = new LinearGradientBrush(rect, DesignTitleBaseColor, DesignTitleLightingColor, LinearGradientMode.Horizontal); // graph.FillRectangle(brush, rect); // rect.Inflate(-4, 0); // graph.DrawString(LayerDescription, Font, Brushes.Black, rect); // } //} protected override void OnPaint(PaintEventArgs args) { base.OnPaint(args); // paint selected tool. if (_SelectedTool != null) { _SelectedTool.Tracker.Paint(args); } // paint picking tool. if (PickingTool != null) { PickingTool.Paint(args); } }
protected override void OnMouseDoubleClick(MouseEventArgs args) { base.OnMouseDoubleClick(args); if (PickingTool != null) { PickingTool.Escape(); AddTool(PickingTool); SelectedTool = PickingTool; InvalidateRect(PickingTool.SurroundingRect); PickingTool = null; } else if (SelectedTool != null) { SelectedTool.OnMouseDoubleClick(this, args); } }
protected override void OnMouseMove(MouseEventArgs pArgs) { base.OnMouseMove(pArgs); Point lLocation = GetScrollablePoint(pArgs.Location); switch (pArgs.Button) { case MouseButtons.Right: return; case MouseButtons.None: Cursor lCurrentCursor = Cursors.Hand; if (SelectedToolboxItem == null && PickingTool == null) { DrawingTools.Any(e => { Cursor lCursor = e.Tracker.GetCursor(lLocation); bool lRet = false; if (lCursor != Cursors.Default) { lCurrentCursor = lCursor; lRet = true; } return(lRet); }); } else { lCurrentCursor = Cursors.Cross; } Cursor.Current = lCurrentCursor; break; case MouseButtons.Left: if (FullDragMode) { return; } bool lRunDefault = true; if (SelectedTool != null) { DrawingTracker lTracker = SelectedTool.Tracker; lRunDefault = false; // stretching on tracker. if (lTracker.IsResizing) { InvalidateRect(lTracker.SurroundingRect); lTracker.Resize(lLocation); InvalidateRect(lTracker.SurroundingRect); } else if (DragBoxFromMouseDown != Rectangle.Empty) { // start DragDrop on selected tool object. if (!DragBoxFromMouseDown.Contains(lLocation)) { int dx = GraphicsMapper.Instance.TransformInt(DraggingPoint.X - SelectedTool.SurroundingRect.Left, CoordinateSpace.Device, CoordinateSpace.Page); int dy = GraphicsMapper.Instance.TransformInt(DraggingPoint.Y - SelectedTool.SurroundingRect.Top, CoordinateSpace.Device, CoordinateSpace.Page); using (new DragImage(SelectedTool.GetDraggingImage(LayerWidth, LayerHeight), dx, dy)) { int lIndex = DrawingTools.IndexOf(SelectedTool); DoDragDrop(lIndex.ToString(), DragDropEffects.All); DraggingPoint = Point.Empty; DragBoxFromMouseDown = Rectangle.Empty; } } } else { lRunDefault = true; } } // update current Cursor. if (lRunDefault) { if (PickingTool == null) { ToolboxItem lItem = SelectedToolboxItem; // update cursor by hitTest on each drawing tool. if (lItem != null && DragBoxFromMouseDown != Rectangle.Empty) { // create toolbox item if (!DragBoxFromMouseDown.Contains(lLocation)) { PickingTool = lItem.CreateComponents(DesignerHost).FirstOrDefault() as DrawingTool; PickingTool.CreatePersistence(); PickingTool.StartResize(lLocation); } } } } break; } if (PickingTool != null) { InvalidateRect(PickingTool.SurroundingRect); PickingTool.Resize(lLocation); InvalidateRect(PickingTool.SurroundingRect); } }