private void suiteTreeView_ItemDrag(object sender, ItemDragEventArgs e)
        {
            this.dragNode = (TreeNode)e.Item;
            this.suiteTreeView.SelectedNode = this.dragNode;

            this.imageListDrag.Images.Clear();
            this.imageListDrag.ImageSize = new Size(this.dragNode.Bounds.Size.Width + this.suiteTreeView.Indent, this.dragNode.Bounds.Height);

            Bitmap   bmp = new Bitmap(this.dragNode.Bounds.Width + this.suiteTreeView.Indent, this.dragNode.Bounds.Height);
            Graphics gfx = Graphics.FromImage(bmp);

            gfx.DrawImage(this.treeViewImages.Images[0], 0, 0);
            gfx.DrawString(this.dragNode.Text, this.suiteTreeView.Font, new SolidBrush(this.suiteTreeView.ForeColor), (float)this.suiteTreeView.Indent, 1.0f);

            this.imageListDrag.Images.Add(bmp);

            Point p = this.suiteTreeView.PointToClient(Control.MousePosition);

            int dx = p.X + this.suiteTreeView.Indent - this.dragNode.Bounds.Left;
            int dy = p.Y - this.dragNode.Bounds.Top;

            if (DragHelper.ImageList_BeginDrag(this.imageListDrag.Handle, 0, dx, dy))
            {
                this.suiteTreeView.DoDragDrop(bmp, DragDropEffects.Move);
                DragHelper.ImageList_EndDrag();
            }
        }
Beispiel #2
0
        protected override void OnItemDrag(ItemDragEventArgs e)
        {
            try
            {
                // Get drag node and select it
                this.dragNode = (TreeNode)e.Item;

                this.SelectedNode = this.dragNode;

                // Reset image list used for drag image
                this.imageListDrag.Images.Clear();
                this.imageListDrag.ImageSize = new Size(this.dragNode.Bounds.Size.Width + this.Indent, this.dragNode.Bounds.Height);

                // Create new bitmap
                // This bitmap will contain the tree node image to be dragged
                Bitmap bmp = new Bitmap(this.dragNode.Bounds.Width + this.Indent, this.dragNode.Bounds.Height);

                // Get graphics from bitmap
                Graphics gfx = Graphics.FromImage(bmp);

                // Draw node icon into the bitmap
                if (this.ImageList != null)
                {
                    this.imageListDrag.ColorDepth = this.ImageList.ColorDepth;

                    gfx.DrawImage(this.ImageList.Images[this.dragNode.ImageIndex], 0, 0);

                    // Draw node label into bitmap
                    gfx.DrawString(this.dragNode.Text,
                                   this.Font,
                                   new SolidBrush(this.ForeColor),
                                   (float)this.Indent, 1.0f);
                }
                // Add bitmap to imagelist
                this.imageListDrag.Images.Add(bmp);

                // Get mouse position in client coordinates
                Point p = this.PointToClient(Control.MousePosition);

                // Compute delta between mouse position and node bounds
                int dx = p.X + this.Indent - this.dragNode.Bounds.Left;
                int dy = p.Y - this.dragNode.Bounds.Top;

                // Begin dragging image
                if (DragHelper.ImageList_BeginDrag(this.imageListDrag.Handle, 0, dx, dy))
                {
                    // Begin dragging
                    this.DoDragDrop(bmp, DragDropEffects.Move);
                    // End dragging image
                    DragHelper.ImageList_EndDrag();
                }
            }
            catch (Exception ex)
            {
                ACSLog.InsertLog(MessageBoxIcon.Error, ex);
            }
        }
Beispiel #3
0
        private void treeView1_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e)
        {
            dragNode = (TreeNode)e.Item;
            string strItem = dragNode.Name;

            this.imageListDrag.Images.Clear();
            this.imageListDrag.ImageSize = new Size(this.dragNode.Bounds.Size.Width + this.treeView1.Indent, this.dragNode.Bounds.Height);

            Bitmap bmp = new Bitmap(this.dragNode.Bounds.Width + this.treeView1.Indent, this.dragNode.Bounds.Height);



            // Get graphics from bitmap
            Graphics gfx = Graphics.FromImage(bmp);


            gfx.DrawImage(this.imageList1.Images[0], 0, 0);

            // Draw node label into bitmap
            gfx.DrawString(this.dragNode.Text,
                           this.treeView1.Font,
                           new SolidBrush(this.treeView1.ForeColor),
                           (float)this.treeView1.Indent, 1.0f);

            // Add bitmap to imagelist
            this.imageListDrag.Images.Add(bmp);


            Point p = this.treeView1.PointToClient(Control.MousePosition);

            // Compute delta between mouse position and node bounds
            int dx = p.X + this.treeView1.Indent - this.dragNode.Bounds.Left;
            int dy = p.Y - this.dragNode.Bounds.Top;

            // Begin dragging image
            if (DragHelper.ImageList_BeginDrag(this.imageListDrag.Handle, 0, dx, dy))
            {
                // Begin dragging
                // this.treeView1.DoDragDrop(bmp, DragDropEffects.Move);

                DoDragDrop(strItem, DragDropEffects.Move);
                // End dragging image
                DragHelper.ImageList_EndDrag();
            }
        }
Beispiel #4
0
        private void BetterTreeView_ItemDrag(object sender, ItemDragEventArgs e)
        {
            // Get mouse position in client coordinates
            Point p = PointToClient(MousePosition);

            // Get drag node and select it
            dragNode     = (BetterTreeNode)e.Item;
            SelectedNode = dragNode;

            // Create the Graphics object from the node being dragged.
            Bitmap   bmp = new Bitmap(dragNode.Bounds.Width + Indent, dragNode.Bounds.Height);
            Graphics gfx = Graphics.FromImage(bmp);

            // Draw node icon into the bitmap
            gfx.DrawImage(ImageList.Images[dragNode.ImageIndex], 0, 0);

            // Draw node label into bitmap
            gfx.DrawString(dragNode.Text, Font, new SolidBrush(ForeColor), 18f, 1f);

            int dragImageWidth = dragNode.Bounds.Size.Width + Indent;

            if (dragImageWidth > 256)
            {
                dragImageWidth = 256;
            }

            imageListDrag = Helpers.GenerateImageList(new Bitmap[] { bmp },
                                                      dragImageWidth, dragNode.Bounds.Height);

            // Compute delta between mouse position and node bounds
            int dx = p.X + Indent - dragNode.Bounds.Left - Location.X;
            int dy = p.Y - dragNode.Bounds.Top - Location.Y;

            // Begin dragging image
            if (DragHelper.ImageList_BeginDrag(imageListDrag.Handle, 0, dx, dy))
            {
                // Begin dragging
                DoDragDrop(bmp, DragDropEffects.Move);
                // End dragging image
                DragHelper.ImageList_EndDrag();
            }
        }
Beispiel #5
0
        void TemplateTree_ItemDrag(object sender, ItemDragEventArgs e)
        {
            TreeNode Node     = e.Item as TreeNode;
            Boolean  IsModule = Convert.ToBoolean(Node.Tag);

            if (IsModule)
            {
                dragNode = e.Item as TreeNode;
                TemplateTree.SelectedNode = dragNode;

                int imageWidth = dragNode.Bounds.Size.Width + TemplateTree.Indent;

                imageListDrag.Images.Clear();
                imageListDrag.ImageSize = new Size(imageWidth > 255 ? 255 : imageWidth, dragNode.Bounds.Height);

                Bitmap   bmp = new Bitmap(dragNode.Bounds.Width + TemplateTree.Indent, dragNode.Bounds.Height);
                Graphics gfx = Graphics.FromImage(bmp);
                gfx.DrawImage(imageList1.Images[dragNode.ImageIndex], 0, 0);
                gfx.DrawString(dragNode.Text, TemplateTree.Font,
                               new SolidBrush(TemplateTree.ForeColor),
                               (float)TemplateTree.Indent, 1.0f);

                imageListDrag.Images.Add(bmp);

                Point p = TemplateTree.PointToClient(Control.MousePosition);

                int dx = p.X + TemplateTree.Indent - dragNode.Bounds.Left;
                int dy = p.Y - dragNode.Bounds.Top;

                if (DragHelper.ImageList_BeginDrag(imageListDrag.Handle, 0, dx, dy))
                {
                    TemplateTree.DoDragDrop(bmp, DragDropEffects.Move);
                    DragHelper.ImageList_EndDrag();
                }
            }
            else
            {
                return;
            }
        }
            /// <summary>
            /// Gets called when an item starts to be dragged.
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void _ItemDrag(object sender, ItemDragEventArgs e)
            {
                var treeView = sender as TreeView;

                if (treeView == null || treeView != this._treeView)
                {
                    return;
                }

                // do not allow root nodes to be dragged
                if (!this._canDragRootNodes && treeView.Nodes.Contains((TreeNode)e.Item))
                {
                    return;
                }

                // Get drag node and select it
                var treeNode = (TreeNode)e.Item;

                this._draggedNode     = treeNode;
                treeView.SelectedNode = this._draggedNode;

                // Reset image list used for drag image
                var imageList = this._dragImageList;

                imageList.Images.Clear();

                var nodeImage = treeNode.GetImage();

                imageList.ImageSize = new Drawing.Size(Math.Min(256, treeNode.Bounds.Size.Width + (nodeImage?.Width + 1 ?? 0)), Math.Min(256, treeNode.Bounds.Height));

                // Create new bitmap
                // This bitmap will contain the tree node image to be dragged
                var bmp = new Bitmap(imageList.ImageSize.Width, imageList.ImageSize.Height);

                // Get graphics from bitmap
                var gfx = Graphics.FromImage(bmp);

                // Draw node icon into the bitmap
                if (nodeImage != null)
                {
                    gfx.DrawImage(nodeImage, 0, 0);
                }

                // Draw node label into bitmap
                gfx.DrawString(treeNode.Text, treeView.Font, new SolidBrush(treeView.ForeColor), nodeImage?.Width + 1 ?? 0, 1.0f);

                // Add bitmap to imagelist
                imageList.Images.Add(bmp);

                // Compute hotspot
                const int dx = 16;
                const int dy = 16;

                // Begin dragging image
                if (!DragHelper.ImageList_BeginDrag(imageList.Handle, 0, -dx, -dy))
                {
                    return;
                }

                treeView.DoDragDrop(treeNode, DragDropEffects.Move);

                // End dragging image
                DragHelper.ImageList_EndDrag();
            }