diff --git a/Business/Menus.cs b/Business/Menus.cs index f767ba7..1958f51 100644 --- a/Business/Menus.cs +++ b/Business/Menus.cs @@ -745,6 +745,7 @@ namespace SystemTrayMenu.Business if (menu.Level == 0) { menu.ResetSearchText(); + menu.ResetHeight(); AdjustMenusSizeAndLocation(); } } @@ -1391,6 +1392,7 @@ namespace SystemTrayMenu.Business dgv.DataSource = dataTable; hideSubmenuDuringRefreshSearch = false; + menus[0].ResetHeight(); menus[0].RefreshSearchText(); hideSubmenuDuringRefreshSearch = true; } @@ -1429,6 +1431,7 @@ namespace SystemTrayMenu.Business AddItemsToMenu(rowDatas, menus[0], out _, out _); hideSubmenuDuringRefreshSearch = false; + menus[0].ResetHeight(); menus[0].RefreshSearchText(); hideSubmenuDuringRefreshSearch = true; diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index ef2a33f..8e57128 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.3.0.13")] -[assembly: AssemblyFileVersion("1.3.0.13")] +[assembly: AssemblyVersion("1.3.0.14")] +[assembly: AssemblyFileVersion("1.3.0.14")] diff --git a/UserInterface/Menu.cs b/UserInterface/Menu.cs index 13c9076..a38dfcc 100644 --- a/UserInterface/Menu.cs +++ b/UserInterface/Menu.cs @@ -27,6 +27,7 @@ namespace SystemTrayMenu.UserInterface private bool mouseDown; private Point lastLocation; private bool isSetSearchText; + private bool dgvHeightSet; internal Menu() { @@ -678,6 +679,11 @@ namespace SystemTrayMenu.UserInterface } } + internal void ResetHeight() + { + dgvHeightSet = false; + } + internal void SetCounts(int foldersCount, int filesCount) { int filesAndFoldersCount = foldersCount + filesCount; @@ -757,47 +763,35 @@ namespace SystemTrayMenu.UserInterface row.Height = dgv.RowTemplate.Height; } - int dgvHeightNew = dgv.Rows.GetRowsHeight(DataGridViewElementStates.None); - int dgvHeightMax = screenHeightMax - (Height - dgv.Height); - - int heightMaxInPixel = (int)(Scaling.Factor * Scaling.FactorByDpi * + int dgvHeightByItems = dgv.Rows.GetRowsHeight(DataGridViewElementStates.None); + int dgvHeightMaxByScreen = screenHeightMax - (Height - dgv.Height); + int dgvHeightMaxByOptions = (int)(Scaling.Factor * Scaling.FactorByDpi * 450f * (Properties.Settings.Default.HeightMaxInPercent / 100f)); - if (dgvHeightMax > heightMaxInPixel) + int dgvHeightMax = Math.Min(dgvHeightMaxByScreen, dgvHeightMaxByOptions); + if (!dgvHeightSet) { - dgvHeightMax = heightMaxInPixel; + dgv.Height = Math.Min(dgvHeightByItems, dgvHeightMax); + dgvHeightSet = true; } - tableLayoutPanelDgvAndScrollbar.SuspendLayout(); - tableLayoutPanelMenu.SuspendLayout(); - dgv.ScrollBars = ScrollBars.None; - if (dgvHeightNew > dgvHeightMax) + if (dgvHeightByItems > dgvHeightMax) { - // Make all rows fit into the screen - customScrollbar.PaintEnable(dgvHeightMax); - if (customScrollbar.Maximum != dgvHeightNew) + ScrollbarVisible = true; + customScrollbar.PaintEnable(dgv.Height); + if (customScrollbar.Maximum != dgvHeightByItems) { customScrollbar.Reset(); customScrollbar.Minimum = 0; - customScrollbar.Maximum = dgvHeightNew; + customScrollbar.Maximum = dgvHeightByItems; customScrollbar.LargeChange = dgvHeightMax; customScrollbar.SmallChange = dgv.RowTemplate.Height; } - - dgvHeightNew = dgvHeightMax; - ScrollbarVisible = true; } else { - customScrollbar.PaintDisable(); ScrollbarVisible = false; + customScrollbar.PaintDisable(); } - - dgv.Height = dgvHeightNew; - tableLayoutPanelMenu.ResumeLayout(); - tableLayoutPanelDgvAndScrollbar.AutoScroll = false; - tableLayoutPanelDgvAndScrollbar.ResumeLayout(); - tableLayoutPanelMenu.PerformLayout(); - tableLayoutPanelDgvAndScrollbar.PerformLayout(); } private void AdjustDataGridViewWidth()