Exemple #1
0
 //Удаление контрола
 void RecursiveRemoveControl(UserFamilyNodeControl control)
 {
     foreach (UserFamilyNodeControl c in control.Parents)
     {
         RecursiveRemoveControl(c);
     }
     this.Controls.Remove(control);
 }
Exemple #2
0
        void RecursiveAddLines(UserFamilyNodeControl node)
        {
            if (node.LeftParent == null && node.RightParent == null)
            {
                return;
            }
            //Нижняя ветвь
            Rectangle upperRect = new Rectangle(
                node.Location.X + node.Width / 2 - NodeSizes.Offset.Width / 2,
                node.Bottom,
                NodeSizes.Offset.Width,
                NodeSizes.Offset.Height / 2
                );

            path.AddRectangle(upperRect);
            if (node.LeftParent != null)
            {
                //Левая горизонтальная ветвь
                Rectangle middleLeftRect = new Rectangle(
                    node.LeftParent.Location.X + node.Width / 2 - NodeSizes.Offset.Width / 2,
                    upperRect.Bottom - NodeSizes.Offset.Width / 2,
                    node.Left - node.LeftParent.Left + NodeSizes.Offset.Width,
                    NodeSizes.Offset.Width
                    );
                //Левая нижняя ветвь
                Rectangle bottomLeftRect = new Rectangle(
                    middleLeftRect.Left,
                    middleLeftRect.Bottom,
                    NodeSizes.Offset.Width,
                    NodeSizes.Offset.Height / 2
                    );
                path.AddRectangle(middleLeftRect);
                path.AddRectangle(bottomLeftRect);
                RecursiveAddLines(node.LeftParent);
            }
            if (node.RightParent != null)
            {
                //Правая горизонтальная ветвь
                Rectangle middleRightRect = new Rectangle(
                    upperRect.Left,
                    upperRect.Bottom - NodeSizes.Offset.Width / 2,
                    node.RightParent.Right - node.Right + NodeSizes.Offset.Width,
                    NodeSizes.Offset.Width
                    );
                //Правая нижняя ветвь
                Rectangle bottomRightRect = new Rectangle(
                    middleRightRect.Right - NodeSizes.Offset.Width,
                    middleRightRect.Bottom,
                    NodeSizes.Offset.Width,
                    NodeSizes.Offset.Height / 2
                    );
                path.AddRectangle(middleRightRect);
                path.AddRectangle(bottomRightRect);
                RecursiveAddLines(node.RightParent);
            }
        }
 public UserFamilyNodeControl()
 {
     LeftParent  = null;
     RightParent = null;
     Parents     = new List <UserFamilyNodeControl>(2);
     Siblings    = new List <UserFamilyNodeControl>();
     InitializeComponent();
     pictureBox1.MouseClick += PictureBox1_MouseClick;
     label1.MouseClick      += Label1_MouseClick;
 }
Exemple #4
0
        UserFamilyNodeControl CreateNode()
        {
            UserFamilyNodeControl node = new UserFamilyNodeControl();

            node.NodeMouseClick += NodeMouseClick;
            node.NodeName        = "Name";
            node.NodePicture     = defaultImage;
            node.Size            = NodeSizes.NodeSize;
            return(node);
        }
Exemple #5
0
 void InitHead()
 {
     head = new UserFamilyNodeControl();
     head.NodeMouseClick += NodeMouseClick;
     head.NodeName        = "Me";
     head.NodePicture     = defaultImage;
     head.Size            = NodeSizes.NodeSize;
     head.Location        = new Point((ClientRectangle.Right - NodeSizes.NodeSize.Width) / 2, ClientRectangle.Y);
     Controls.Add(head);
 }
Exemple #6
0
 //Рекурсивный проход по дереву до елемента используемый для подсчета коефициента отступа
 void OffsetCoefficient(UserFamilyNodeControl node, UserFamilyNodeControl key, int coef)
 {
     if (node == key)
     {
         coefficient = coef;
         return;
     }
     foreach (UserFamilyNodeControl n in node.Parents)
     {
         OffsetCoefficient(n, key, coef * 2);
     }
 }
Exemple #7
0
 //Удаление из дерева елемента и его ссылок
 void RecursiveRemoveNode(UserFamilyNodeControl node, UserFamilyNodeControl key)
 {
     foreach (UserFamilyNodeControl n in node.Parents)
     {
         RecursiveRemoveNode(n, key);
     }
     node.Parents.Remove(key);
     if (node.LeftParent == key)
     {
         node.LeftParent = null;
     }
     if (node.RightParent == key)
     {
         node.RightParent = null;
     }
 }
Exemple #8
0
 void AddRightParent(object sender, EventArgs e)
 {
     if (clicked.RightParent == null)
     {
         UserFamilyNodeControl node = CreateNode();
         clicked.RightParent = node;
         clicked.Parents.Add(node);
         OffsetCoefficient(head, node, 2);
         if (coefficient > 32)
         {
             return; // выход за реализованый предел
         }
         Point pos = clicked.Location;
         pos.Offset(ClientRectangle.Width / coefficient, NodeSizes.NodeSize.Height + NodeSizes.Offset.Height);
         node.Location = pos;
         Controls.Add(node);
         RefreshTree();
     }
 }
Exemple #9
0
 private void NodeMouseClick(object sender, MouseEventArgs e)
 {
     //Использование указателя на контрол инициатор
     clicked = sender as UserFamilyNodeControl;
     menu.Show(sender as UserFamilyNodeControl, new Point());
 }