private void ToolBarDoubleClick(object sender, System.EventArgs e) { ToolBarDockHolder holder = (ToolBarDockHolder)sender; if (IsDocked(holder)) { ToolBarDockArea docked = GetDockedArea(holder); docked.SuspendLayout(); holder.Parent = holder.FloatForm; holder.Location = new Point(0, 0); holder.DockStyle = DockStyle.None; holder.FloatForm.Visible = true; holder.FloatForm.Size = holder.Size; docked.ResumeLayout(); docked.PerformLayout(); } else { ToolBarDockArea area = holder.PreferredDockedArea; area.SuspendLayout(); Point newLoc = holder.PreferredDockedLocation; holder.DockStyle = area.Dock; holder.Parent = area; holder.PreferredDockedLocation = newLoc; holder.FloatForm.Visible = false; holder.PreferredDockedArea = area; area.ResumeLayout(); area.PerformLayout(); } }
public ToolBarManager(ScrollableControl dockStation, Form mainForm) { this.dockStation = dockStation; this.mainForm = mainForm; _left = new ToolBarDockArea(this, DockStyle.Left); _right = new ToolBarDockArea(this, DockStyle.Right); _top = new ToolBarDockArea(this, DockStyle.Top); _bottom = new ToolBarDockArea(this, DockStyle.Bottom); Application.AddMessageFilter(this); }
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); }
protected ToolBarDockArea GetClosestArea(Point ptScreen, ToolBarDockArea preferred) { if (preferred != null) { Rectangle p = preferred.RectangleToScreen(preferred.ClientRectangle); p.Inflate(8, 8); if (p.Contains(ptScreen)) { return(preferred); } } Rectangle l = _left.RectangleToScreen(_left.ClientRectangle); l.Inflate(8, 8); Rectangle r = _right.RectangleToScreen(_right.ClientRectangle); r.Inflate(8, 8); Rectangle t = _top.RectangleToScreen(_top.ClientRectangle); t.Inflate(8, 8); Rectangle b = _bottom.RectangleToScreen(_bottom.ClientRectangle); b.Inflate(8, 8); if (t.Contains(ptScreen)) { return(_top); } if (b.Contains(ptScreen)) { return(_bottom); } if (l.Contains(ptScreen)) { return(_left); } if (r.Contains(ptScreen)) { return(_right); } return(null); }
public ToolBarDockHolder(ToolBarManager dm, Control c, DockStyle style) { SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true); BackColor = SystemColors.ControlLight; panel = new Panel(); panel.Parent = this; panel.Dock = DockStyle.Fill; panel.Controls.Add(c); DockManager = dm; if (style == DockStyle.Left) { preferredDockedArea = dm.Left; } else if (style == DockStyle.Right) { preferredDockedArea = dm.Right; } else if (style == DockStyle.Bottom) { preferredDockedArea = dm.Bottom; } else { preferredDockedArea = dm.Top; } control = c; FloatForm.Visible = false; FloatForm.FormBorderStyle = FormBorderStyle.None; FloatForm.MaximizeBox = false; FloatForm.MinimizeBox = false; FloatForm.ShowInTaskbar = false; FloatForm.ClientSize = new Size(10, 10); // Added by mav DockManager.MainForm.AddOwnedForm(FloatForm); DockStyle = style; // this will call create() ToolbarTitle = c.Text; }
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; } }