From bc7ad48fc390c26a8e47c008b3a09abb61a2472a Mon Sep 17 00:00:00 2001 From: Lorenz Cuno Klopfenstein Date: Tue, 6 Nov 2012 20:28:06 +0100 Subject: [PATCH] Marginal clean up and fixing of context menu handlers. --- OnTopReplica/MainForm.cs | 4 ++-- OnTopReplica/MainForm_Gui.cs | 32 ++++++++--------------------- OnTopReplica/MainForm_MenuEvents.cs | 9 -------- 3 files changed, 10 insertions(+), 35 deletions(-) diff --git a/OnTopReplica/MainForm.cs b/OnTopReplica/MainForm.cs index d04dcb6..9e8e1d3 100644 --- a/OnTopReplica/MainForm.cs +++ b/OnTopReplica/MainForm.cs @@ -151,7 +151,7 @@ namespace OnTopReplica { //Same story as above (OnMouseDoubleClick) if (e.Button == System.Windows.Forms.MouseButtons.Right) { - OpenContextMenu(); + OpenContextMenu(null); } } @@ -166,7 +166,7 @@ namespace OnTopReplica { case WM.NCRBUTTONUP: //Open context menu if right button clicked on caption (i.e. all of the window area because of glass) if (m.WParam.ToInt32() == HT.CAPTION) { - OpenContextMenu(); + OpenContextMenu(null); m.Result = IntPtr.Zero; return; diff --git a/OnTopReplica/MainForm_Gui.cs b/OnTopReplica/MainForm_Gui.cs index cf7b094..39141fb 100644 --- a/OnTopReplica/MainForm_Gui.cs +++ b/OnTopReplica/MainForm_Gui.cs @@ -8,36 +8,20 @@ namespace OnTopReplica { /// /// Opens the context menu. /// - public void OpenContextMenu() { + /// Optional position of the mouse, relative to which the menu is shown. + public void OpenContextMenu(Point? position) { + Point menuPosition = MousePosition; + if (position.HasValue) + menuPosition = position.Value; + if (IsFullscreen) { - menuFullscreenContext.Show(MousePosition); + menuFullscreenContext.Show(menuPosition); } else { - menuContext.Show(MousePosition); + menuContext.Show(menuPosition); } } - private Point RecenterLocation(Control original, Control final) { - int origX = original.Location.X + original.Size.Width / 2; - int origY = original.Location.Y + original.Size.Height / 2; - - int finX = origX - final.Size.Width / 2; - int finY = origY - final.Size.Height / 2; - - //Check boundaries - var screen = Screen.FromControl(final); - if (finX < screen.WorkingArea.X) - finX = screen.WorkingArea.X; - if (finX + final.Size.Width > screen.WorkingArea.Width) - finX = screen.WorkingArea.Width - final.Size.Width; - if (finY < screen.WorkingArea.Y) - finY = screen.WorkingArea.Y; - if (finY + final.Size.Height > screen.WorkingArea.Height) - finY = screen.WorkingArea.Height - final.Size.Height; - - return new Point(finX, finY); - } - /// /// Gets the window's vertical chrome size. /// diff --git a/OnTopReplica/MainForm_MenuEvents.cs b/OnTopReplica/MainForm_MenuEvents.cs index d699af8..fbf6d99 100644 --- a/OnTopReplica/MainForm_MenuEvents.cs +++ b/OnTopReplica/MainForm_MenuEvents.cs @@ -165,15 +165,6 @@ namespace OnTopReplica { } private void Menu_About_click(object sender, EventArgs e) { - /*this.Hide(); - - using (var box = new AboutForm()) { - box.Location = RecenterLocation(this, box); - box.ShowDialog(); - Location = RecenterLocation(box, this); - } - - this.Show();*/ this.SetSidePanel(new AboutPanel()); }