예제 #1
0
        void SetupActiveBoxProperties(LayoutFarm.CustomWidgets.EaseBox box)
        {
            //1. mouse down         
            box.MouseDown += (s, e) =>
            {
                //box.BackColor = KnownColors.FromKnownColor(KnownColor.DeepSkyBlue);
                e.MouseCursorStyle = MouseCursorStyle.Pointer;
                //--------------------------------------------
                //request user controller for this box 

                if (this.BoxSelectionMode == DzBoardSample.BoxSelectionMode.Single)
                {
                    RemoveAllControllerBoxes();
                }

                var userControllerBox = GetFreeControllerBox();
                userControllerBox.TargetBox = box;
                //--------
                //get position relative to box
                var loca1 = box.GetGlobalLocation();
                userControllerBox.SetLocation(loca1.X - 5, loca1.Y - 5);
                userControllerBox.SetSize(box.Width + 10, box.Height + 10);
                userControllerBox.Visible = true;
                userControllerBox.Focus();
                e.SetMouseCapture(userControllerBox);
                e.StopPropagation();
                //--------------------------------------------
            };
            //2. mouse up
            box.MouseUp += (s, e) =>
            {
                e.MouseCursorStyle = MouseCursorStyle.Default;
                //box.BackColor = Color.LightGray;
                RemoveAllControllerBoxes();
                e.StopPropagation();
            };
        }
 void SetupActiveBoxProperties(LayoutFarm.CustomWidgets.EaseBox box)
 {
     //1. mouse down         
     box.MouseDown += (s, e) =>
     {
         box.BackColor = KnownColors.FromKnownColor(KnownColor.DeepSkyBlue);
         e.MouseCursorStyle = MouseCursorStyle.Pointer;
         UIControllerBox userControllerBox = null;
         if (this.controllerBoxMode == ControllerBoxMode.MultipleBoxes)
         {
             //multiple box
             userControllerBox = GetFreeUserControllerBox();
         }
         else
         {
             //single box
             if (singleControllerBox != null)
             {
                 ReleaseUserControllerBox(singleControllerBox);
             }
             //get new one
             userControllerBox = singleControllerBox = GetFreeUserControllerBox();
         }
         //request user controller for this box
         userControllerBox.TargetBox = box;
         viewport.AddContent(userControllerBox);
         //location relative to global position of target box
         var globalTargetPos = box.GetGlobalLocation();
         userControllerBox.SetLocation(globalTargetPos.X - 5, globalTargetPos.Y - 5);
         userControllerBox.SetSize(box.Width + 10, box.Height + 10);
         userControllerBox.Visible = true;
         //move mouse capture to new controller box
         //for next drag
         e.SetMouseCapture(userControllerBox);
     };
     //2. mouse up
     box.MouseUp += (s, e) =>
     {
         e.MouseCursorStyle = MouseCursorStyle.Default;
         box.BackColor = Color.LightGray;
         RemoveAllUserControllerBoxes();
     };
     box.DragOver += (s, e) =>
     {
         switch (e.UserMsgFlags)
         {
             case 1:
                 {   //sample only
                     box.BackColor = Color.Green;
                 }
                 break;
             case 2:
                 {
                     //sample only
                     //leaving
                     box.BackColor = Color.Blue;
                 }
                 break;
             case 3:
                 {
                     //drop
                     var sender = e.Sender as UIControllerBox;
                     var droppingBox = sender.TargetBox as UIBox;
                     if (droppingBox != null)
                     {
                         //move from original 
                         var parentBox = droppingBox.ParentUI as LayoutFarm.CustomWidgets.SimpleBox;
                         if (parentBox != null)
                         {
                             var newParentGlobalLoca = box.GetGlobalLocation();
                             var droppingGlobalLoca = droppingBox.GetGlobalLocation();
                             parentBox.RemoveChild(droppingBox);
                             box.AddChild(droppingBox);
                             //TODO: review here , 
                             //set location relative to other element
                             droppingBox.SetLocation(
                                 droppingGlobalLoca.X - newParentGlobalLoca.X,
                                 droppingGlobalLoca.Y - newParentGlobalLoca.Y);
                         }
                         else
                         {
                         }
                     }
                 }
                 break;
         }
     };
 }