Esempio n. 1
0
        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            int     H          = 0;
            int     W          = 0;
            GObject GContainer = new GObject();
            GObject GToDrag    = new GObject();

            GToDrag = GNetwork.GObjects[CurrObjDragIndx];
            double   d1     = 0;
            double   d2     = 0;
            TimeSpan DTDrag = new TimeSpan();

            DTDrag = DateTime.Now.Subtract(Tdown);
            if ((Dragging == true) && (DTDrag.Milliseconds > DragTimeMin))
            {
                if ((GNetwork.GObjects[CurrObjDragIndx].Type == "Line") &&
                    (GNetwork.FindContainerObject(e.X, e.Y, ref GContainer, true) > -1))
                {
                    //
                    //    What is the point of the line to link ?
                    //    The nearest to (Xdown,Ydown)
                    //
                    d1 = CommFnc.distance(Xdown, Ydown, GToDrag.x1, GToDrag.y1);
                    d2 = CommFnc.distance(Xdown, Ydown, GToDrag.x2, GToDrag.y2);
                    if (d1 <= d2)
                    {
                        GToDrag.x1   = (GContainer.x1 + GContainer.x2) / 2;
                        GToDrag.y1   = (GContainer.y1 + GContainer.y2) / 2;
                        GToDrag.Lnk1 = GContainer.Name;
                    }
                    else
                    {
                        GToDrag.x2   = (GContainer.x1 + GContainer.x2) / 2;
                        GToDrag.y2   = (GContainer.y1 + GContainer.y2) / 2;
                        GToDrag.Lnk2 = GContainer.Name;
                    }
                }
                else
                {
                    W          = GToDrag.x2 - GToDrag.x1;
                    H          = GToDrag.y2 - GToDrag.y1;
                    GToDrag.x1 = e.X;
                    GToDrag.y1 = e.Y;
                    GToDrag.x2 = e.X + W;
                    GToDrag.y2 = e.Y + H;
                    GNetwork.AdjustLinkedTo(GToDrag.Name);
                }
                Cursor.Current = Cursors.Default;
                Dragging       = false;
                this.Refresh();
            }
        }
Esempio n. 2
0
        public void MouseObject(MouseEventArgs e)
        {
            int     H          = 0;
            int     W          = 0;
            GObject GContainer = new GObject();
            GObject GToDrag    = new GObject();

            GToDrag = GNetwork.GObjects[CurrObjDragIndx];//取出該元件實體
            double   d1     = 0;
            double   d2     = 0;
            TimeSpan DTDrag = new TimeSpan();

            DTDrag = DateTime.Now.Subtract(Tdown);//計算時間間隔
            if ((Dragging == true) && (DTDrag.Milliseconds > DragTimeMin))
            {
                if ((GNetwork.GObjects[CurrObjDragIndx].Type == "Line") &&
                    (GNetwork.FindContainerObject(e.X, e.Y, ref GContainer, true) > -1))
                {
                    //
                    //    What is the point of the line to link ?
                    //    The nearest to (Xdown,Ydown)
                    //
                    d1 = CommFnc.distance(Xdown, Ydown, GToDrag.x1, GToDrag.y1);
                    d2 = CommFnc.distance(Xdown, Ydown, GToDrag.x2, GToDrag.y2);
                    if (d1 <= d2)
                    {
                        GToDrag.x1   = (GContainer.x1 + GContainer.x2) / 2;
                        GToDrag.y1   = (GContainer.y1 + GContainer.y2) / 2;
                        GToDrag.Lnk1 = GContainer.Name;
                    }
                    else
                    {
                        GToDrag.x2   = (GContainer.x1 + GContainer.x2) / 2;
                        GToDrag.y2   = (GContainer.y1 + GContainer.y2) / 2;
                        GToDrag.Lnk2 = GContainer.Name;
                    }
                }
                else
                {
                    W          = GToDrag.x2 - GToDrag.x1; //移動元件的位置計算
                    H          = GToDrag.y2 - GToDrag.y1; //移動元件的位置計算
                    GToDrag.x1 = e.X;                     //移動元件的位置計算
                    GToDrag.y1 = e.Y;                     //移動元件的位置計算
                    GToDrag.x2 = e.X + W;                 //移動元件的位置計算
                    GToDrag.y2 = e.Y + H;                 //移動元件的位置計算
                    GNetwork.AdjustLinkedTo(GToDrag.Name);
                }

                this.Refresh();//觸發重繪
            }
        }