//Target
 private void StartMovingOrResizing(Control control, MouseEventArgs e, MoveOrResize WorkType)
 {
     MiMFa_ControlService.SetControlThreadSafe(control, new Action <object[]>((oa) =>
     {
         if (_moving || _resizing)
         {
             return;
         }
         if (WorkType != MoveOrResize.Move &&
             (MouseIsInRightEdge || MouseIsInLeftEdge || MouseIsInTopEdge || MouseIsInBottomEdge))
         {
             _resizing = true;
             _currentControlStartSize = control.Size;
         }
         else if (WorkType != MoveOrResize.Resize)
         {
             control.Dock   = DockStyle.None;
             _moving        = true;
             control.Cursor = Cursors.SizeAll;
         }
         else
         {
             control.Cursor = Cursors.Default;
         }
         _cursorStartPoint = new Point(e.X, e.Y);
         control.Capture   = true;
         _draging          = true;
     }), new object[] { });
 }
Beispiel #2
0
 internal static void Stop(Control control)
 {
     control.MouseDown -= (sender, e) => StartMovingOrResizing(control, e);
     control.MouseUp   -= (sender, e) => StopDragOrResizing(control);
     control.MouseMove -= (sender, e) => MoveControl(control, e);
     WorkType           = MoveOrResize.None;
     UpdateMouseCursor(control);
 }
 public static void Stop( )
 {
     _resizing = false;
     _moving   = false;
     ControlMoverOrResizer.WorkType = MoveOrResize.None;
     //control.MouseDown -= (sender, e) => StartMovingOrResizing(control, e);
     //control.MouseUp -= (sender, e) => StopDragOrResizing(control);
     //control.MouseMove -= (sender, e) => MoveControl(control, e);
 }
 public void AddControl(MoveOrResize moveOrResize, params Control[] controls)
 {
     if (controls != null)
     {
         for (int i = 0; i < controls.Length; i++)
         {
             AddControl(controls[i], controls[i], moveOrResize);
         }
     }
 }
 public MiMFa_ObjectMoveOrResize(MoveOrResize moveOrResize = MoveOrResize.MoveAndResize, params Control[] controls)
 {
     if (controls != null)
     {
         foreach (var item in controls)
         {
             AddControl(item, item, moveOrResize);
         }
     }
 }
Beispiel #6
0
 internal static void Init(Control control, Control container)
 {
     _moving             = false;
     _resizing           = false;
     _moveIsInterNal     = false;
     _cursorStartPoint   = Point.Empty;
     MouseIsInLeftEdge   = false;
     MouseIsInLeftEdge   = false;
     MouseIsInRightEdge  = false;
     MouseIsInTopEdge    = false;
     MouseIsInBottomEdge = false;
     WorkType            = MoveOrResize.MoveAndResize;
     control.MouseDown  += (sender, e) => StartMovingOrResizing(control, e);
     control.MouseUp    += (sender, e) => StopDragOrResizing(control);
     control.MouseMove  += (sender, e) => MoveControl(container, e);
 }
Beispiel #7
0
 // Control and container control is the one that is dragable anf the container is the parretn of the dragable control so EX: drag container only when you drag the button inside the container
 internal static void Init(Control control, Control container) // Initialize // Settings for the Selected Control
 {
     _moving             = false;
     _resizing           = false;
     _moveIsInterNal     = false;
     _cursorStartPoint   = Point.Empty;
     MouseIsInLeftEdge   = false;
     MouseIsInLeftEdge   = false;
     MouseIsInRightEdge  = false;
     MouseIsInTopEdge    = false;
     MouseIsInBottomEdge = false;
     WorkType            = MoveOrResize.MoveAndResize;
     control.MouseDown  += (sender, e) => StartMovingOrResizing(control, e); //#### Setts Mouse Events to the selected Control
     control.MouseUp    += (sender, e) => StopDragOrResizing(control);
     control.MouseMove  += (sender, e) => MoveControl(container, e);
 }
 private void StopDragOrResizing(Control control, MoveOrResize WorkType)
 {
     MiMFa_ControlService.SetControlThreadSafe(control, new Action <object[]>((oa) =>
     {
         control.Dock        = _currentControlDock;
         _draging            = false;
         _resizing           = false;
         _moving             = false;
         control.Capture     = false;
         MouseIsInLeftEdge   = false;
         MouseIsInRightEdge  = false;
         MouseIsInTopEdge    = false;
         MouseIsInBottomEdge = false;
         UpdateMouseCursor(control, WorkType);
     }), new object[] { });
 }
 internal static void Unload(Control control, Control container)
 {
     _moving             = false;
     _resizing           = false;
     _moveIsInterNal     = false;
     _cursorStartPoint   = Point.Empty;
     MouseIsInLeftEdge   = false;
     MouseIsInLeftEdge   = false;
     MouseIsInRightEdge  = false;
     MouseIsInTopEdge    = false;
     MouseIsInBottomEdge = false;
     WorkType            = MoveOrResize.MoveAndResize;
     control.RemoveEvents("Event" + nameof(control.MouseDown));
     control.RemoveEvents("Event" + nameof(control.MouseUp));
     control.RemoveEvents("Event" + nameof(control.MouseMove));
     _enabled = false;
 }
 private void UpdateMouseCursor(Control control, MoveOrResize WorkType)
 {
     if (WorkType == MoveOrResize.Move)
     {
         return;
     }
     else if (MouseIsInLeftEdge)
     {
         if (MouseIsInTopEdge)
         {
             control.Cursor = Cursors.SizeNWSE;
         }
         else if (MouseIsInBottomEdge)
         {
             control.Cursor = Cursors.SizeNESW;
         }
         else
         {
             control.Cursor = Cursors.SizeWE;
         }
     }
     else if (MouseIsInRightEdge)
     {
         if (MouseIsInTopEdge)
         {
             control.Cursor = Cursors.SizeNESW;
         }
         else if (MouseIsInBottomEdge)
         {
             control.Cursor = Cursors.SizeNWSE;
         }
         else
         {
             control.Cursor = Cursors.SizeWE;
         }
     }
     else if (MouseIsInTopEdge || MouseIsInBottomEdge)
     {
         control.Cursor = Cursors.SizeNS;
     }
     else
     {
         control.Cursor = Cursors.Default;
     }
 }
 internal static void Init(Control control, Control container)
 {
     _moving = false;
     _resizing = false;
     _moveIsInterNal = false;
     _cursorStartPoint = Point.Empty;
     MouseIsInLeftEdge = false;
     MouseIsInLeftEdge = false;
     MouseIsInRightEdge = false;
     MouseIsInTopEdge = false;
     MouseIsInBottomEdge = false;
     WorkType = MoveOrResize.MoveAndResize;
     control.MouseDown += (sender, e) => StartMovingOrResizing(control, e);
     control.MouseUp += (sender, e) => StopDragOrResizing(control);
     control.MouseMove += (sender, e) => MoveControl(container, e);
 }
 private void UpdateMouseEdgeProperties(Control control, Point mouseLocationInControl, MoveOrResize WorkType)
 {
     if (WorkType == MoveOrResize.Move)
     {
         return;
     }
     MouseIsInLeftEdge   = Math.Abs(mouseLocationInControl.X) <= 4;
     MouseIsInRightEdge  = Math.Abs(mouseLocationInControl.X - control.Width) <= 4;
     MouseIsInTopEdge    = Math.Abs(mouseLocationInControl.Y) <= 4;
     MouseIsInBottomEdge = Math.Abs(mouseLocationInControl.Y - control.Height) <= 4;
 }
        public void AddControl(Control control, Control container /*Moved Container*/, MoveOrResize moveOrResize = MoveOrResize.MoveAndResize)
        {
            _moving             = false;
            _resizing           = false;
            _moveIsInterNal     = false;
            _cursorStartPoint   = Point.Empty;
            MouseIsInLeftEdge   = false;
            MouseIsInLeftEdge   = false;
            MouseIsInRightEdge  = false;
            MouseIsInTopEdge    = false;
            MouseIsInBottomEdge = false;

            control.MouseEnter += (sender, e) => { _currentControlDock = control.Dock; };
            control.MouseDown  += (sender, e) => StartMovingOrResizing(control, e, moveOrResize);
            control.MouseUp    += (sender, e) => StopDragOrResizing(control, moveOrResize);
            control.MouseLeave += (sender, e) => StopDragOrResizing(control, moveOrResize);
            control.MouseMove  += (sender, e) => MoveControl(container, e, moveOrResize);
        }
 public void AddControl(Control control, MoveOrResize moveOrResize = MoveOrResize.MoveAndResize)
 {
     AddControl(control, control, moveOrResize);
 }
 private void MoveControl(Control control, MouseEventArgs e, MoveOrResize WorkType)
 {
     MiMFa_ControlService.SetControlThreadSafe(control, new Action <object[]>((oa) =>
     {
         if ((!_resizing && !_moving) || !_draging)
         {
             _resizing = _moving = _draging;
             UpdateMouseEdgeProperties(control, new Point(e.X, e.Y), WorkType);
             UpdateMouseCursor(control, WorkType);
         }
         if (_resizing)
         {
             if (MouseIsInLeftEdge)
             {
                 if (MouseIsInTopEdge)
                 {
                     control.Width  -= (e.X - _cursorStartPoint.X);
                     control.Left   += (e.X - _cursorStartPoint.X);
                     control.Height -= (e.Y - _cursorStartPoint.Y);
                     control.Top    += (e.Y - _cursorStartPoint.Y);
                 }
                 else if (MouseIsInBottomEdge)
                 {
                     control.Width -= (e.X - _cursorStartPoint.X);
                     control.Left  += (e.X - _cursorStartPoint.X);
                     control.Height = (e.Y - _cursorStartPoint.Y) + _currentControlStartSize.Height;
                 }
                 else
                 {
                     control.Width -= (e.X - _cursorStartPoint.X);
                     control.Left  += (e.X - _cursorStartPoint.X);
                 }
             }
             else if (MouseIsInRightEdge)
             {
                 if (MouseIsInTopEdge)
                 {
                     control.Width   = (e.X - _cursorStartPoint.X) + _currentControlStartSize.Width;
                     control.Height -= (e.Y - _cursorStartPoint.Y);
                     control.Top    += (e.Y - _cursorStartPoint.Y);
                 }
                 else if (MouseIsInBottomEdge)
                 {
                     control.Width  = (e.X - _cursorStartPoint.X) + _currentControlStartSize.Width;
                     control.Height = (e.Y - _cursorStartPoint.Y) + _currentControlStartSize.Height;
                 }
                 else
                 {
                     control.Width = (e.X - _cursorStartPoint.X) + _currentControlStartSize.Width;
                 }
             }
             else if (MouseIsInTopEdge)
             {
                 control.Height -= (e.Y - _cursorStartPoint.Y);
                 control.Top    += (e.Y - _cursorStartPoint.Y);
             }
             else if (MouseIsInBottomEdge)
             {
                 control.Height = (e.Y - _cursorStartPoint.Y) + _currentControlStartSize.Height;
             }
             else
             {
                 StopDragOrResizing(control, WorkType);
             }
         }
         else if (_moving)
         {
             _moveIsInterNal = !_moveIsInterNal;
             if (!_moveIsInterNal)
             {
                 int x            = (e.X - _cursorStartPoint.X) + control.Left;
                 int y            = (e.Y - _cursorStartPoint.Y) + control.Top;
                 control.Location = new Point(x, y);
             }
         }
     }), new object[] { });
 }