Exemplo n.º 1
0
        /// <summary>
        /// Draws all arrows of this pair
        /// </summary>
        /// <param name="g">The graphics to draw</param>
        public void SetArrows(Graphics g)
        {
            object[] arrs = arrows.ToArray();
            int      n    = arrs.Length;
            int      xs   = 0;
            int      ys   = 0;
            int      xt   = 0;
            int      yt   = 0;
            Control  p    = null;

            if (objects[0] is Panel | objects[0] is UserControl)
            {
                p = objects[0] as Control;
            }
            else
            {
                p = ContainerPerformer.GetPanel(objects[0]) as Control;
            }
            xs = p.Left + p.Width / 2;
            ys = p.Top + p.Height / 2;
            if (objects[1] is Panel | objects[1] is UserControl)
            {
                p = objects[1] as Control;
            }
            else
            {
                p = ContainerPerformer.GetPanel(objects[1]) as Control;
            }
            if (p == null)
            {
                return;
            }
            xt = p.Left + p.Width / 2;
            yt = p.Top + p.Height / 2;
            int    xc   = (xt + xs) / 2;
            int    yc   = (yt + ys) / 2;
            int    dx   = (xt - xs) / 2;
            int    dy   = (yt - ys) / 2;
            double d    = Math.Sqrt((double)(dx * dx + dy * dy));
            double px   = -DISTANCE * ((double)dy) / d;
            double py   = DISTANCE * ((double)dx) / d;
            int    posX = xc - (int)((n - 1) * px / 2);
            int    posY = yc - (int)((n - 1) * py / 2);

            for (int i = 0; i < n; i++)
            {
                IArrowLabelUI lab     = arrs[i] as IArrowLabelUI;
                Control       control = lab.Control as Control;
                lab.X = posX + i * (int)px - control.Width / 2;
                lab.Y = posY + i * (int)py - control.Height / 2;
                if (g == null)
                {
                    continue;
                }
                lab.Draw(g);
            }
        }