[Feature] Option to appear at mouse location (#135), version 1.0.17.25

This commit is contained in:
Markus Hofknecht 2021-04-28 22:58:33 +02:00
parent 49907998bb
commit 7914950c9f
5 changed files with 32 additions and 10 deletions

View file

@ -862,20 +862,26 @@ namespace SystemTrayMenu.Business
private void AdjustMenusSizeAndLocation() private void AdjustMenusSizeAndLocation()
{ {
WindowsTaskbar taskbar = new WindowsTaskbar(); Rectangle screenBounds;
Menu menuPredecessor = null; if (Properties.Settings.Default.AppearAtMouseLocation)
List<Menu> list = AsList; {
Menu menu; screenBounds = Screen.FromPoint(Cursor.Position).Bounds;
Rectangle screenBounds = Screen.PrimaryScreen.Bounds; }
Menu.StartLocation startLocation; else
{
screenBounds = Screen.PrimaryScreen.Bounds;
}
// Only apply taskbar position change when no menu is currently open // Only apply taskbar position change when no menu is currently open
List<Menu> list = AsList;
WindowsTaskbar taskbar = new WindowsTaskbar();
if (list.Count == 1) if (list.Count == 1)
{ {
taskbarPosition = taskbar.Position; taskbarPosition = taskbar.Position;
} }
// Shrink the usable space depending on taskbar location // Shrink the usable space depending on taskbar location
Menu.StartLocation startLocation;
switch (taskbarPosition) switch (taskbarPosition)
{ {
case TaskbarPosition.Left: case TaskbarPosition.Left:
@ -899,6 +905,8 @@ namespace SystemTrayMenu.Business
break; break;
} }
Menu menu;
Menu menuPredecessor = null;
for (int i = 0; i < list.Count; i++) for (int i = 0; i < list.Count; i++)
{ {
menu = list[i]; menu = list[i];

View file

@ -39,5 +39,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.17.24")] [assembly: AssemblyVersion("1.0.17.25")]
[assembly: AssemblyFileVersion("1.0.17.24")] [assembly: AssemblyFileVersion("1.0.17.25")]

View file

@ -241,7 +241,6 @@
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118"> <PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View file

@ -301,6 +301,15 @@ namespace SystemTrayMenu.UserInterface
// Ignore start as we use predecessor // Ignore start as we use predecessor
startLocation = StartLocation.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 // Update the height and width
AdjustDataGridViewHeight(menuPredecessor, bounds.Height); AdjustDataGridViewHeight(menuPredecessor, bounds.Height);
@ -349,6 +358,13 @@ namespace SystemTrayMenu.UserInterface
break; 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 // Calculate Y position
int y; int y;
switch (startLocation) switch (startLocation)

View file

@ -545,7 +545,6 @@ namespace SystemTrayMenu.UserInterface
// //
this.checkBoxAppearAtMouseLocation.AutoSize = true; this.checkBoxAppearAtMouseLocation.AutoSize = true;
this.checkBoxAppearAtMouseLocation.Dock = System.Windows.Forms.DockStyle.Fill; this.checkBoxAppearAtMouseLocation.Dock = System.Windows.Forms.DockStyle.Fill;
this.checkBoxAppearAtMouseLocation.Enabled = false;
this.checkBoxAppearAtMouseLocation.Location = new System.Drawing.Point(3, 3); this.checkBoxAppearAtMouseLocation.Location = new System.Drawing.Point(3, 3);
this.checkBoxAppearAtMouseLocation.Name = "checkBoxAppearAtMouseLocation"; this.checkBoxAppearAtMouseLocation.Name = "checkBoxAppearAtMouseLocation";
this.checkBoxAppearAtMouseLocation.Size = new System.Drawing.Size(438, 19); this.checkBoxAppearAtMouseLocation.Size = new System.Drawing.Size(438, 19);