Exemplo n.º 1
0
 public bool PreFilterMessage(ref Message m)
 {
     if (m.Msg == WM_KEYDOWN)
     {
         Keys keyCode = (Keys)(int)m.WParam & Keys.KeyCode;
         if (keyCode == Keys.ControlKey)
         {
             if (!_ctrlDown && _dragged != null && IsDocked(_dragged))
             {
                 ToolBarDockArea docked = GetDockedArea(_dragged);
                 docked.SuspendLayout();
                 _dragged.Parent             = _dragged.FloatForm;
                 _dragged.Location           = new Point(0, 0);
                 _dragged.DockStyle          = DockStyle.None;
                 _dragged.FloatForm.Visible  = true;
                 _dragged.FloatForm.Location = new Point(Control.MousePosition.X - _ptOffset.X, Control.MousePosition.Y - 8);
                 _dragged.FloatForm.Size     = _dragged.Size;
                 docked.ResumeLayout();
                 docked.PerformLayout();
             }
             _ctrlDown = true;
         }
     }
     else if (m.Msg == WM_KEYUP)
     {
         Keys keyCode = (Keys)(int)m.WParam & Keys.KeyCode;
         if (keyCode == Keys.ControlKey)
         {
             if (_ctrlDown && _dragged != null && !IsDocked(_dragged))
             {
                 ToolBarDockArea closest = GetClosestArea(Control.MousePosition, _dragged.PreferredDockedArea);
                 if (closest != null)
                 {
                     closest.SuspendLayout();
                     Point newLoc = closest.PointToClient(Control.MousePosition);
                     _dragged.DockStyle = closest.Dock;
                     _dragged.Parent    = closest;
                     _dragged.PreferredDockedLocation = newLoc;
                     _dragged.FloatForm.Visible       = false;
                     _dragged.PreferredDockedArea     = closest;
                     closest.ResumeLayout();
                     closest.PerformLayout();
                 }
             }
             _ctrlDown = false;
         }
     }
     return(false);
 }
Exemplo n.º 2
0
        private void ToolBarMouseMove(object sender, MouseEventArgs e)
        {
            Point ptPos = new Point(e.X, e.Y);

            if (_dragged != null)
            {
                Point ptDelta = new Point(_ptStart.X - Control.MousePosition.X, _ptStart.Y - Control.MousePosition.Y);

                Point newLoc = _dragged.PointToScreen(new Point(0, 0));
                newLoc = new Point(newLoc.X - ptDelta.X, newLoc.Y - ptDelta.Y);
                ToolBarDockArea closest = GetClosestArea(Control.MousePosition, _dragged.PreferredDockedArea);
                // Added by mav
                if (closest != null && !_dragged.IsAllowed(closest.Dock))
                {
                    closest = null;
                }

                ToolBarDockArea docked = GetDockedArea(_dragged);

                if (_ctrlDown)
                {
                    closest = null;
                }

                if (docked != null)
                {
                    if (closest == null)
                    {
                        docked.SuspendLayout();
                        _dragged.Parent             = _dragged.FloatForm;
                        _dragged.Location           = new Point(0, 0);
                        _dragged.DockStyle          = DockStyle.None;
                        _dragged.FloatForm.Visible  = true;
                        _dragged.FloatForm.Location = new Point(Control.MousePosition.X - _ptOffset.X, Control.MousePosition.Y - 8);
                        _dragged.FloatForm.Size     = _dragged.Size;
                        docked.ResumeLayout();
                        docked.PerformLayout();
                    }
                    else if (closest != docked)
                    {
                        closest.SuspendLayout();
                        newLoc             = closest.PointToClient(Control.MousePosition);
                        _dragged.DockStyle = closest.Dock;
                        _dragged.Parent    = closest;
                        _dragged.PreferredDockedLocation = newLoc;
                        _dragged.FloatForm.Visible       = false;
                        _dragged.PreferredDockedArea     = closest;
                        closest.ResumeLayout();
                        closest.PerformLayout();
                    }
                    else
                    {
                        closest.SuspendLayout();
                        newLoc = closest.PointToClient(Control.MousePosition);
//						if(closest.Horizontal)
//							newLoc = new Point(newLoc.X - 4, newLoc.Y - _dragged.Height/2);
//						else
//							newLoc = new Point(newLoc.X - _dragged.Width/2, newLoc.Y - 4);
                        _dragged.PreferredDockedLocation = newLoc;
                        closest.ResumeLayout();
                        closest.PerformLayout();
                    }
                }
                else
                {
                    if (closest == null)
                    {
                        _dragged.FloatForm.Location = newLoc;
                    }
                    else
                    {
                        closest.SuspendLayout();
                        newLoc             = closest.PointToClient(Control.MousePosition);
                        _dragged.DockStyle = closest.Dock;
                        _dragged.Parent    = closest;
                        _dragged.PreferredDockedLocation = newLoc;
                        _dragged.FloatForm.Visible       = false;
                        _dragged.PreferredDockedArea     = closest;
                        closest.ResumeLayout();
                        closest.PerformLayout();
                    }
                }
                _ptStart = Control.MousePosition;
            }
        }