コード例 #1
0
        /// <summary>
        /// Handles the DragDrop event of contained RichTextBox object.
        /// Process text changes on drop event.
        /// </summary>
        /// <param name="sender">The reference to contained RichTextBox object.</param>
        /// <param name="e">The event arguments.</param>
        void OnDragDrop(object sender, DragEventArgs e)
        {
            // Check if the picked item is the one we added to the toolbox.
            if (e.Data.GetDataPresent(typeof(Toolbox_TestItem1)))
            {
                GraphEditorPackage.PutTextToCS("Console.WriteLine(\"T1\");");

                Toolbox_TestItem1 myData = (Toolbox_TestItem1)e.Data.GetData(typeof(Toolbox_TestItem1));


                UserControl_Node n = new UserControl_Node("T1");
                n.Location = this.PointToClient(Cursor.Position);

                this.Controls.Add(n);

                // Specify DragDrop result
                e.Effect = DragDropEffects.Copy;
            }

            else if (e.Data.GetDataPresent(typeof(Toolbox_TestItem2)))
            {
                GraphEditorPackage.PutTextToCS("Console.WriteLine(\"T2\");");

                UserControl_Node n = new UserControl_Node("T2");
                n.Location = this.PointToClient(Cursor.Position);

                this.Controls.Add(n);

                // Specify DragDrop result
                e.Effect = DragDropEffects.Copy;
            }


            else if (e.Data.GetData(DataFormats.StringFormat).ToString().StartsWith("UserControl_Node"))
            {
                string   s          = e.Data.GetData(DataFormats.StringFormat).ToString();
                string[] tokens     = s.Split('|');
                string   GuidString = tokens[1];

                foreach (Control c in this.Controls)
                {
                    if (c.GetType() == typeof(UserControl_Node))
                    {
                        UserControl_Node uc = (UserControl_Node)c;
                        if (uc.Guid.ToString() == GuidString)
                        {
                            Point newPlace = new Point(
                                Cursor.Position.X - uc.PointMouseDown.X
                                , Cursor.Position.Y - uc.PointMouseDown.Y);
                            uc.Location = this.PointToClient(newPlace);
                        }
                    }
                }
                // Specify DragDrop result
                e.Effect = DragDropEffects.Move;
            }
        }
コード例 #2
0
        /// <summary>
        /// Handles the DragDrop event of contained RichTextBox object.
        /// Process text changes on drop event.
        /// </summary>
        /// <param name="sender">The reference to contained RichTextBox object.</param>
        /// <param name="e">The event arguments.</param>
        void OnDragDrop(object sender, DragEventArgs e)
        {
            // Check if the picked item is the one we added to the toolbox.
            if (e.Data.GetDataPresent(typeof(Toolbox_TestItem1)))
            {
                Toolbox_TestItem1 myData = (Toolbox_TestItem1)e.Data.GetData(typeof(Toolbox_TestItem1));
                editorControl.Text += "w";

                // Specify DragDrop result
                e.Effect = DragDropEffects.Copy;
            }
        }
コード例 #3
0
        /// <summary>
        /// Sends notification that an item in the Toolbox is selected through a click, or by pressing ENTER.
        /// </summary>
        /// <param name="pDO">Data object that is selected.</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        int IVsToolboxUser.ItemPicked(IOleDataObject pDO)
        {
            // Create a OleDataObject from the input interface.
            OleDataObject oleData = new OleDataObject(pDO);

            // Check if the picked item is the one we added to the toolbox.
            if (oleData.GetDataPresent(typeof(Toolbox_TestItem1)))
            {
                Debug.WriteLine("MyToolboxItemData selected from the toolbox");
                Toolbox_TestItem1 myData = (Toolbox_TestItem1)oleData.GetData(typeof(Toolbox_TestItem1));
                //editorControl.Text += myData.Content;
            }
            return(VSConstants.S_OK);
        }