From fd34b400e119868239ab43cdd2dd6927f35692b4 Mon Sep 17 00:00:00 2001 From: Markus Hofknecht Date: Sat, 6 Jun 2020 19:50:01 +0200 Subject: [PATCH] Fix using direction when reach screen border (#94) --- Business/Menus.cs | 2 +- UserInterface/Menu.cs | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Business/Menus.cs b/Business/Menus.cs index c4f9835..8526867 100644 --- a/Business/Menus.cs +++ b/Business/Menus.cs @@ -757,7 +757,7 @@ namespace SystemTrayMenu.Business widthPredecessors -= newWith; } - menu.AdjustSizeAndLocation(menuPredecessor); + menu.AdjustSizeAndLocation(menuPredecessor, directionToRight); widthPredecessors += menu.Width - menu.Padding.Left; menuPredecessor = menu; } diff --git a/UserInterface/Menu.cs b/UserInterface/Menu.cs index 54f9b41..09af8fd 100644 --- a/UserInterface/Menu.cs +++ b/UserInterface/Menu.cs @@ -237,7 +237,8 @@ namespace SystemTrayMenu.UserInterface } } - internal void AdjustSizeAndLocation(Menu menuPredecessor = null) + internal void AdjustSizeAndLocation(Menu menuPredecessor = null, + bool directionToRight = false) { if (!dgvAutoResizeRowDone) { @@ -272,9 +273,24 @@ namespace SystemTrayMenu.UserInterface } else { - x = menuPredecessor.Location.X - Width + - (int)Math.Round(Scaling.Factor, 0, - MidpointRounding.AwayFromZero); + if (directionToRight) + { + x = menuPredecessor.Location.X + Width - + (int)Math.Round(Scaling.Factor, 0, + MidpointRounding.AwayFromZero); + } + else + { + x = menuPredecessor.Location.X - Width + + (int)Math.Round(Scaling.Factor, 0, + MidpointRounding.AwayFromZero); + } + } + + if (x < 0) + { + x += menuPredecessor.Width; + x += Width; } int y;