コード例 #1
0
 protected void MoveThisObj(Classes.SenderObjForEvent senderObj, EventArgs e)
 {
     if (moveThisObj != null)
     {
         moveThisObj(senderObj, e);
     }
 }
コード例 #2
0
        private void ObjectMyControl_newLocation(object sender, EventArgs e)
        {
            Classes.SenderObjForEvent objLocationPointToScreen = (Classes.SenderObjForEvent)sender;
            var  eventObj = (Classes.MyUserControl)objLocationPointToScreen.ObjectEvent;
            bool childer  = false;

            foreach (Control item in this.Controls)//на передний план.
            {
                if (item == eventObj)
                {
                    childer = true;
                }
            }
            if (!childer)
            {
                this.Controls.Add(eventObj);

                this.UpdateZOrder();
            }
            eventObj.BringToFront();

            System.Drawing.Point CursorPosition =
                new Point(x: this.PointToClient(Cursor.Position).X,
                          y: this.PointToClient(Cursor.Position).Y);
            System.Drawing.Point newLocationObj =
                new Point(x: CursorPosition.X - objLocationPointToScreen.LocationCursorInObj.X,
                          y: CursorPosition.Y - objLocationPointToScreen.LocationCursorInObj.Y);
            System.Drawing.Point PatrentLocation =
                new Point(x: eventObj.Parent.Location.X,
                          y: eventObj.Parent.Location.Y);

            //Control PaterControl = eventObj.Parent;
            //Control BigPaterControl = null;
            //if(PaterControl.GetType()!=eventObj.pa)

            System.Drawing.Point CursorLocationForParent =
                new Point(x: this.Parent.PointToClient(Cursor.Position).X,
                          y: this.Parent.PointToClient(Cursor.Position).Y);


            if (this.Parent.PointToClient(Cursor.Position).X < eventObj.Parent.Location.X ||
                this.Parent.PointToClient(Cursor.Position).Y < eventObj.Parent.Location.Y ||
                this.Parent.PointToClient(Cursor.Position).X > eventObj.Parent.Location.X + eventObj.Parent.Size.Width ||
                this.Parent.PointToClient(Cursor.Position).Y > eventObj.Parent.Location.Y + eventObj.Parent.Size.Height)
            {
            }
            else
            {
                eventObj.Location = new Point(newLocationObj.X, newLocationObj.Y);
            }
        }