From 7914950c9f2aa644a6a9348468060a9b49172b56 Mon Sep 17 00:00:00 2001 From: Markus Hofknecht Date: Wed, 28 Apr 2021 22:58:33 +0200 Subject: [PATCH] [Feature] Option to appear at mouse location (#135), version 1.0.17.25 --- Business/Menus.cs | 20 ++++++++++++++------ Properties/AssemblyInfo.cs | 4 ++-- SystemTrayMenu.csproj | 1 - UserInterface/Menu.cs | 16 ++++++++++++++++ UserInterface/SettingsForm.Designer.cs | 1 - 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/Business/Menus.cs b/Business/Menus.cs index b47e9dd..1cdd384 100644 --- a/Business/Menus.cs +++ b/Business/Menus.cs @@ -862,20 +862,26 @@ namespace SystemTrayMenu.Business private void AdjustMenusSizeAndLocation() { - WindowsTaskbar taskbar = new WindowsTaskbar(); - Menu menuPredecessor = null; - List list = AsList; - Menu menu; - Rectangle screenBounds = Screen.PrimaryScreen.Bounds; - Menu.StartLocation startLocation; + Rectangle screenBounds; + if (Properties.Settings.Default.AppearAtMouseLocation) + { + screenBounds = Screen.FromPoint(Cursor.Position).Bounds; + } + else + { + screenBounds = Screen.PrimaryScreen.Bounds; + } // Only apply taskbar position change when no menu is currently open + List list = AsList; + WindowsTaskbar taskbar = new WindowsTaskbar(); if (list.Count == 1) { taskbarPosition = taskbar.Position; } // Shrink the usable space depending on taskbar location + Menu.StartLocation startLocation; switch (taskbarPosition) { case TaskbarPosition.Left: @@ -899,6 +905,8 @@ namespace SystemTrayMenu.Business break; } + Menu menu; + Menu menuPredecessor = null; for (int i = 0; i < list.Count; i++) { menu = list[i]; diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 5956738..25072a0 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -39,5 +39,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.17.24")] -[assembly: AssemblyFileVersion("1.0.17.24")] +[assembly: AssemblyVersion("1.0.17.25")] +[assembly: AssemblyFileVersion("1.0.17.25")] diff --git a/SystemTrayMenu.csproj b/SystemTrayMenu.csproj index 3974e43..4bdd538 100644 --- a/SystemTrayMenu.csproj +++ b/SystemTrayMenu.csproj @@ -241,7 +241,6 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/UserInterface/Menu.cs b/UserInterface/Menu.cs index 39e197f..ebecfa5 100644 --- a/UserInterface/Menu.cs +++ b/UserInterface/Menu.cs @@ -301,6 +301,15 @@ namespace SystemTrayMenu.UserInterface // Ignore start as we use predecessor startLocation = StartLocation.Predecessor; } + else if (Properties.Settings.Default.AppearAtMouseLocation) + { + // Use this menu as predecessor and set location of Mouse + menuPredecessor = this; + Tag = new RowData(); + Location = new Point(Cursor.Position.X, Cursor.Position.Y - labelTitle.Height); + directionToRight = true; + startLocation = StartLocation.Predecessor; + } // Update the height and width AdjustDataGridViewHeight(menuPredecessor, bounds.Height); @@ -349,6 +358,13 @@ namespace SystemTrayMenu.UserInterface break; } + // X position for click, remove width of this menu as it is used as predecessor + if (menuPredecessor == this && directionToRight) + { + x -= Width; + directionToRight = false; + } + // Calculate Y position int y; switch (startLocation) diff --git a/UserInterface/SettingsForm.Designer.cs b/UserInterface/SettingsForm.Designer.cs index 26a403a..130c8bf 100644 --- a/UserInterface/SettingsForm.Designer.cs +++ b/UserInterface/SettingsForm.Designer.cs @@ -545,7 +545,6 @@ namespace SystemTrayMenu.UserInterface // this.checkBoxAppearAtMouseLocation.AutoSize = true; this.checkBoxAppearAtMouseLocation.Dock = System.Windows.Forms.DockStyle.Fill; - this.checkBoxAppearAtMouseLocation.Enabled = false; this.checkBoxAppearAtMouseLocation.Location = new System.Drawing.Point(3, 3); this.checkBoxAppearAtMouseLocation.Name = "checkBoxAppearAtMouseLocation"; this.checkBoxAppearAtMouseLocation.Size = new System.Drawing.Size(438, 19);