[Feature] Reset 'Custom location' after display changed event e.g. rdp and custom location not more within screen bounds (#269, #281), version 1.2.0.6

This commit is contained in:
Markus Hofknecht 2021-12-27 12:22:52 +01:00
parent 0d393684a0
commit a102c968f3
4 changed files with 31 additions and 11 deletions

View file

@ -76,6 +76,8 @@ namespace SystemTrayMenu
{
AppRestart.ByDisplaySettings();
}
menus.ReAdjustSizeAndLocation();
}
private void TaskbarForm_Deactivate(object sender, EventArgs e)

View file

@ -647,6 +647,14 @@ namespace SystemTrayMenu.Business
}
}
internal void ReAdjustSizeAndLocation()
{
if (menus[0].IsUsable)
{
menus[0].Tag = null;
}
}
internal void MainPreload()
{
IconReader.MainPreload = true;
@ -1242,6 +1250,7 @@ namespace SystemTrayMenu.Business
private void AdjustMenusSizeAndLocation()
{
Rectangle screenBounds;
bool isCustomLocationOutsideOfScreen = false;
if (Properties.Settings.Default.AppearAtMouseLocation)
{
screenBounds = Screen.FromPoint(Cursor.Position).Bounds;
@ -1251,6 +1260,9 @@ namespace SystemTrayMenu.Business
screenBounds = Screen.FromPoint(new Point(
Properties.Settings.Default.CustomLocationX,
Properties.Settings.Default.CustomLocationY)).Bounds;
isCustomLocationOutsideOfScreen = !screenBounds.Contains(
new Point(Properties.Settings.Default.CustomLocationX, Properties.Settings.Default.CustomLocationY));
}
else
{
@ -1290,7 +1302,8 @@ namespace SystemTrayMenu.Business
break;
}
if (Properties.Settings.Default.AppearAtTheBottomLeft)
if (Properties.Settings.Default.AppearAtTheBottomLeft ||
isCustomLocationOutsideOfScreen)
{
startLocation = Menu.StartLocation.BottomLeft;
}
@ -1304,12 +1317,12 @@ namespace SystemTrayMenu.Business
// Only last one has to be updated as all previous one were already updated in the past
if (list.Count - 1 == i)
{
menu.AdjustSizeAndLocation(screenBounds, menuPredecessor, startLocation);
menu.AdjustSizeAndLocation(screenBounds, menuPredecessor, startLocation, isCustomLocationOutsideOfScreen);
}
else
{
// workaround added also as else, because need adjust scrollbar after search
menu.AdjustSizeAndLocation(screenBounds, menuPredecessor, startLocation);
menu.AdjustSizeAndLocation(screenBounds, menuPredecessor, startLocation, isCustomLocationOutsideOfScreen);
}
if (!Properties.Settings.Default.AppearAtTheBottomLeft &&

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
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0.5")]
[assembly: AssemblyFileVersion("1.2.0.5")]
[assembly: AssemblyVersion("1.2.0.6")]
[assembly: AssemblyFileVersion("1.2.0.6")]

View file

@ -375,23 +375,26 @@ namespace SystemTrayMenu.UserInterface
/// <param name="bounds">Screen coordinates where the menu is allowed to be drawn in.</param>
/// <param name="menuPredecessor">Predecessor menu (when available).</param>
/// <param name="startLocation">Defines where the first menu is drawn (when no predecessor is set).</param>
/// <param name="isCustomLocationOutsideOfScreen">isCustomLocationOutsideOfScreen.</param>
internal void AdjustSizeAndLocation(
Rectangle bounds,
Menu menuPredecessor,
StartLocation startLocation)
StartLocation startLocation,
bool isCustomLocationOutsideOfScreen)
{
// Update the height and width
AdjustDataGridViewHeight(menuPredecessor, bounds.Height);
AdjustDataGridViewWidth();
bool useCustomLocation = Properties.Settings.Default.UseCustomLocation || lastLocation.X > 0;
bool changeDirectionWhenOutOfBounds = true;
if (menuPredecessor != null)
{
// Ignore start as we use predecessor
startLocation = StartLocation.Predecessor;
}
else if (useCustomLocation)
else if (useCustomLocation && !isCustomLocationOutsideOfScreen)
{
// Do not adjust location again because Cursor.Postion changed
if (Tag != null)
@ -407,6 +410,7 @@ namespace SystemTrayMenu.UserInterface
Properties.Settings.Default.CustomLocationY);
directionToRight = true;
startLocation = StartLocation.Predecessor;
changeDirectionWhenOutOfBounds = false;
}
else if (Properties.Settings.Default.AppearAtMouseLocation)
{
@ -422,6 +426,7 @@ namespace SystemTrayMenu.UserInterface
Location = new Point(Cursor.Position.X, Cursor.Position.Y - labelTitle.Height);
directionToRight = true;
startLocation = StartLocation.Predecessor;
changeDirectionWhenOutOfBounds = false;
}
// Calculate X position
@ -435,8 +440,8 @@ namespace SystemTrayMenu.UserInterface
{
x = menuPredecessor.Location.X + menuPredecessor.Width - scaling;
// Change direction when out of bounds
if (bounds.X + bounds.Width <= x + Width - scaling)
if (changeDirectionWhenOutOfBounds &&
bounds.X + bounds.Width <= x + Width - scaling)
{
x = menuPredecessor.Location.X - Width + scaling;
directionToRight = !directionToRight;
@ -446,8 +451,8 @@ namespace SystemTrayMenu.UserInterface
{
x = menuPredecessor.Location.X - Width + scaling;
// Change direction when out of bounds
if (x < bounds.X)
if (changeDirectionWhenOutOfBounds &&
x < bounds.X)
{
x = menuPredecessor.Location.X + menuPredecessor.Width - scaling;
directionToRight = !directionToRight;