Exemple #1
0
        /// <summary>
        /// Handles the Drag event which raises a DoDragDrop event used by the
        /// DesignSurface to drag items from the Toolbox to the DesignSurface.
        /// If the currently selected item is the pointer item then the drag drop
        /// operation is not started.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnItemDrag(object sender, ItemDragEventArgs e)
        {
            if (e.Button == MouseButtons.Left &&
                e.Item.GetType() == typeof(ListViewItem))
            {
                ToolboxItem lItem = (e.Item as ListViewItem).Tag as ToolboxItem;

                if (lItem.TypeName != NameConsts.Pointer)
                {
                    mIsDragging = true;

                    IToolboxService lToolboxService = mToolboxService as IToolboxService;
                    object          lDataObject     = lToolboxService.SerializeToolboxItem(lItem);
                    DrawingTool     lTool           = lItem.CreateComponents().FirstOrDefault() as DrawingTool;

                    lTool.CreatePersistence();
                    Rectangle lRect = lTool.SurroundingRect;

                    using (DragImage image = new DragImage(lTool.DefaultImage, lRect.Width / 2, lRect.Height / 2))
                    {
                        DoDragDrop(lDataObject, DragDropEffects.All);
                    }

                    mIsDragging = false;
                }
            }
        }
Exemple #2
0
        protected override void OnDragDrop(DragEventArgs pArgs)
        {
            base.OnDragDrop(pArgs);

            // drag DrawingTool & drop.
            if (DraggingPoint != Point.Empty)
            {
                string data = pArgs.Data.GetData(typeof(string)) as string;

                data.Split(',').All(e =>
                {
                    int lIndex = Convert.ToInt32(e);
                    DrawingTool lDrawingTool = DrawingTools[lIndex];
                    Point lPoint             = GetScrollablePoint(PointToClient(new Point(pArgs.X, pArgs.Y)));

                    InvalidateRect(lDrawingTool.Tracker.SurroundingRect);
                    lDrawingTool.DoDrop(new Point(lPoint.X - DraggingPoint.X, lPoint.Y - DraggingPoint.Y));
                    InvalidateRect(lDrawingTool.Tracker.SurroundingRect);
                    SelectedTool = lDrawingTool;

                    return(true);
                });

                IsDirty = true;
            }
            else
            {
                // drag ToolboxItem & drop.
                ToolboxItem lItem = GetService <IToolboxService>().DeserializeToolboxItem(pArgs.Data);
                DrawingTool lTool = lItem.CreateComponents(DesignerHost).FirstOrDefault() as DrawingTool;

                if (lTool != null)
                {
                    lTool.CreatePersistence();
                    Point     lLocation = GetScrollablePoint(PointToClient(new Point(pArgs.X, pArgs.Y)));
                    Rectangle lRect     = lTool.SurroundingRect;

                    lLocation.Offset(-lRect.Width / 2, -lRect.Height / 2);
                    lTool.Location = lLocation;
                    AddTool(lTool);
                    SelectedTool = lTool;
                    InvalidateRect(lTool.SurroundingRect);
                }
            }
        }