コード例 #1
0
ファイル: Form2.cs プロジェクト: JorisBosma/TestProject
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //This will create a completely new node and add it to the project
            string Name    = txtName.Text;
            Node   newNode = new Node(Name);

            if (Name == "")
            {
                return;
            }
            if (radioButton1.Checked == true)
            {
                newNode = new Device(Name);
            }
            else if (radioButton2.Checked == true)
            {
                string type = cboxType.SelectedItem.ToString();
                newNode = new Signal(Name, type);
            }
            MyTreeNode newTreeNode = new MyTreeNode(newNode);

            newTreeNode.Text = newNode.sNode;
            pNode.nNode.AddNode(newNode);
            if ((pNode.nNode.GetClass() == "Device" && newNode.GetClass() != "Signal") || (pNode.nNode.GetClass() == "Node" && newNode.GetClass() == "Signal") || (pNode.nNode.GetClass() == "Signal"))
            {
                return;
            }
            else
            {
                pNode.Nodes.Add(newTreeNode);
            }
            pNode.Expand();
        }
コード例 #2
0
ファイル: Form2.cs プロジェクト: JorisBosma/TestProject
        private void treeView_lib_f2_DragDrop(object sender, DragEventArgs e)
        {
            TreeView treeView = sender as TreeView;

            // Retrieve the client coordinates of the drop location.
            Point targetPoint = treeView.PointToClient(new Point(e.X, e.Y));

            // Retrieve the node at the drop location.
            MyTreeNode targetNode = (MyTreeNode)treeView.GetNodeAt(targetPoint);

            // Retrieve the node that was dragged.
            MyTreeNode draggedNode = (MyTreeNode)e.Data.GetData(typeof(MyTreeNode));

            // Confirm that the node at the drop location is not
            // the dragged node or a descendant of the dragged node.
            if (targetNode == null)
            {
                targetNode = (MyTreeNode)treeView.Nodes[0];                     //als jij niet op een node sleept, targetNode wordt rootnode
            }
            if (!draggedNode.Equals(targetNode) && !ContainsNode(draggedNode, targetNode))
            {
                // If it is a move operation, remove the node from its current
                // location and add it to the node at the drop location.
                if (e.Effect == DragDropEffects.Move)
                {
                    draggedNode.Remove();
                    targetNode.Nodes.Add(draggedNode);
                }

                // If it is a copy operation, clone the dragged node
                // and add it to the node at the drop location.
                else if (e.Effect == DragDropEffects.Copy)
                {
                    targetNode.Nodes.Add((MyTreeNode)draggedNode.Clone());
                }

                // Expand the node at the location
                // to show the dropped node.
                targetNode.Expand();
            }
        }
コード例 #3
0
ファイル: Form2.cs プロジェクト: JorisBosma/TestProject
        private void button2_Click(object sender, EventArgs e)
        {
            //ADD TO LIBRARY
            //pNode becomes the selectedNode from the lib
            MyTreeNode SelectedNode = (MyTreeNode)treeView_lib_f2.SelectedNode;
            string     Name         = txtName.Text;
            Node       newNode      = new Node(Name);

            if (Name == null)
            {
                return;
            }
            if (radioButton1.Checked == true)
            {
                newNode = new Device(Name);
            }
            else if (radioButton2.Checked == true)
            {
                string type = cboxType.SelectedItem.ToString();
                newNode = new Signal(Name, type);
            }
            MyTreeNode newTreeNode = new MyTreeNode(newNode);

            newTreeNode.Text = newNode.sNode;
            SelectedNode.nNode.AddNode(newNode);
            //pNode.nNode.AddNode(newNode);
            if ((SelectedNode.nNode.GetClass() == "Device" && newNode.GetClass() != "Signal") || (SelectedNode.nNode.GetClass() == "Node" && newNode.GetClass() == "Signal") || (SelectedNode.nNode.GetClass() == "Signal"))
            {
                return;
            }
            else
            {
                SelectedNode.Nodes.Add(newTreeNode);
            }
            SelectedNode.Expand();
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: JorisBosma/TestProject
        public void treeView_DragDrop(object sender, DragEventArgs e)
        {
            TreeView treeView = sender as TreeView;

            // Retrieve the client coordinates of the drop location.
            Point targetPoint = treeView.PointToClient(new Point(e.X, e.Y));

            // Retrieve the node at the drop location.
            MyTreeNode targetNode = (MyTreeNode)treeView.GetNodeAt(targetPoint);

            // Retrieve the node that was dragged.
            MyTreeNode draggedNode = (MyTreeNode)e.Data.GetData(typeof(MyTreeNode));

            // Confirm that the node at the drop location is not
            // the dragged node or a descendant of the dragged node.
            if (targetNode == null)
            {
                targetNode = (MyTreeNode)treeView.Nodes[0];                     //als jij niet op een node sleept, targetNode wordt rootnode
            }
            if (!draggedNode.Equals(targetNode) && !ContainsNode(draggedNode, targetNode))
            {
                // If it is a move operation, remove the node from its current
                // location and add it to the node at the drop location.
                if (e.Effect == DragDropEffects.Move)
                {
                    if (targetNode.nNode.GetClass() == "Signal" && draggedNode.nNode.GetClass() == "Signal")
                    {
                        Signal sTarget  = (Signal)targetNode.nNode;
                        Signal sDragged = (Signal)draggedNode.nNode;
                        sTarget.Connect(sDragged);

                        MyTreeNode t       = (MyTreeNode)targetNode.Parent;
                        Device     parentD = (Device)t.nNode;
                        //System.Console.WriteLine("Connected: "+sTarget.ConnectedSignal.sNode + sDragged.ConnectedSignal.sNode);
                        targetNode.ForeColor  = System.Drawing.Color.Green;
                        draggedNode.ForeColor = System.Drawing.Color.Green;
                        //refresh tree
                        MyTreeNode treeRoot = (MyTreeNode)treeView_proj.Nodes[0];
                        Node       root     = treeRoot.nNode;
                        loadColors(treeRoot);
                        treeView_sig.Nodes.Clear();
                        PopulateSigTree(root);
                        //sTarget.Disconnnect(sDragged);
                        //System.Console.WriteLine("Connected: " + sTarget.ConnectedSignal.sNode + sDragged.ConnectedSignal.sNode);
                    }
                    if ((targetNode.nNode.GetClass() == "Device" && draggedNode.nNode.GetClass() != "Signal") || (targetNode.nNode.GetClass() == "Node" && draggedNode.nNode.GetClass() == "Signal") || (targetNode.nNode.GetClass() == "Signal"))
                    {
                        return;
                    }
                    else
                    {
                        //Remove and Add node in Data
                        MyTreeNode parentNode = (MyTreeNode)draggedNode.Parent;
                        // MyTreeNode cloneNode = (MyTreeNode)draggedNode.Clone();
                        if (parentNode == null)
                        {
                            return;
                        }
                        parentNode.nNode.RemoveNode(draggedNode.nNode);
                        targetNode.nNode.AddNode(draggedNode.nNode);
                        //Remove and Add node in the tree
                        //Always do this after manipulating the data, otherwise the parentNode is not accurate
                        draggedNode.Remove();
                        targetNode.Nodes.Add(draggedNode); //Put dragged node on top (bottom is default)
                    }
                }
                // Expand the node at the location
                // to show the dropped node.
                targetNode.Expand();
            }
        }