diff --git a/Business/App.cs b/Business/App.cs index f0f8bfa..fda12b4 100644 --- a/Business/App.cs +++ b/Business/App.cs @@ -59,10 +59,17 @@ namespace SystemTrayMenu public void Dispose() { - taskbarForm?.Dispose(); - SystemEvents.DisplaySettingsChanged -= (s, e) => SystemEvents_DisplaySettingsChanged(); - menus.Dispose(); - menuNotifyIcon.Dispose(); + if (taskbarForm?.InvokeRequired == true) + { + Dispose(); + } + else + { + taskbarForm?.Dispose(); + SystemEvents.DisplaySettingsChanged -= (s, e) => SystemEvents_DisplaySettingsChanged(); + menus.Dispose(); + menuNotifyIcon.Dispose(); + } } private void SystemEvents_DisplaySettingsChanged() diff --git a/Business/Menus.cs b/Business/Menus.cs index d82febb..f767ba7 100644 --- a/Business/Menus.cs +++ b/Business/Menus.cs @@ -90,6 +90,7 @@ namespace SystemTrayMenu.Business workerMainMenu.DoWork -= LoadMenu; menus[0] = Create(menuData, Path.GetFileName(Config.Path)); menus[0].HandleCreated += (s, e) => ExecuteWatcherHistory(); + Scaling.CalculateFactorByDpi(menus[0].GetDataGridView().CreateGraphics()); IconReader.MainPreload = false; if (showMenuAfterMainPreload) { diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 05fc391..9896a0c 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.7")] -[assembly: AssemblyFileVersion("1.3.0.7")] +[assembly: AssemblyVersion("1.3.0.8")] +[assembly: AssemblyFileVersion("1.3.0.8")] diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs index 5769094..c975118 100644 --- a/Properties/Settings.Designer.cs +++ b/Properties/Settings.Designer.cs @@ -159,7 +159,7 @@ namespace SystemTrayMenu.Properties [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Configuration.SettingsProviderAttribute(typeof(CustomSettingsProvider))] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("125")] + [global::System.Configuration.DefaultSettingValueAttribute("100")] public int SizeInPercent { get diff --git a/README.md b/README.md index b54e7ab..3573b22 100644 --- a/README.md +++ b/README.md @@ -275,7 +275,7 @@ Thanks for ideas, reporting issues and contributing! #285 #286 [dao-net](https://github.com/dao-net), #288 William P., #294 #295 #296 Stefan Mahrer, -#225 #297 #299 #317 #321 #324 #330 #386 #390 #401 #402 #407 #409 #414 #416 [chip33](https://github.com/chip33), +#225 #297 #299 #317 #321 #324 #330 #386 #390 #401 #402 #407 #409 #414 #416 #418 [chip33](https://github.com/chip33), #298 [phanirithvij](https://github.com/phanirithvij), #306 [wini2](https://github.com/wini2), #370 [dna5589](https://github.com/dna5589), diff --git a/UserInterface/AppContextMenu.cs b/UserInterface/AppContextMenu.cs index e022aa1..bf20005 100644 --- a/UserInterface/AppContextMenu.cs +++ b/UserInterface/AppContextMenu.cs @@ -89,7 +89,7 @@ namespace SystemTrayMenu.Helper aboutBox.AppMoreInfo += "#235 #242 243 #247, #271 Tom, #237 Torsten S., #240 video Patrick, #244 Gunter D., #246 #329 MACE4GITHUB, #259 #310 vanjac, "; aboutBox.AppMoreInfo += "#262 terencemcdonnell, #269 petersnows25, #272 Peter M., #273 #274 ParasiteDelta, #275 #276 #278 donaldaken, "; aboutBox.AppMoreInfo += "#277 Jan S., #282 akuznets, #283 #284 #289 RuSieg, #285 #286 dao-net, #288 William P., #294 #295 #296 Stefan Mahrer, "; - aboutBox.AppMoreInfo += "#225 #297 #299 #317 #321 #324 #330 #386 #390 #401 #402 #407 #409 #414 #416 chip33, #298 phanirithvij, #306 wini2, #370 dna5589, #372 not-nef, #376 Michelle H. "; + aboutBox.AppMoreInfo += "#225 #297 #299 #317 #321 #324 #330 #386 #390 #401 #402 #407 #409 #414 #416 #418 chip33, #298 phanirithvij, #306 wini2, #370 dna5589, #372 not-nef, #376 Michelle H. "; aboutBox.AppMoreInfo += "#377 SoenkeHob, #380 #394 TransLucida, #384 boydfields, #386 visusys, #387 #411 yrctw" + Environment.NewLine; aboutBox.AppMoreInfo += @" Sponsors - Thank you! diff --git a/UserInterface/Menu.ControlsTheDesignerRemoves.cs b/UserInterface/Menu.ControlsTheDesignerRemoves.cs index b76c3d5..2e355d1 100644 --- a/UserInterface/Menu.ControlsTheDesignerRemoves.cs +++ b/UserInterface/Menu.ControlsTheDesignerRemoves.cs @@ -55,7 +55,7 @@ namespace SystemTrayMenu.UserInterface ColumnIcon.DataPropertyName = "ColumnIcon"; dataGridViewCellStyle1.Alignment = DataGridViewContentAlignment.MiddleCenter; dataGridViewCellStyle1.NullValue = "System.Drawing.Icon"; - dataGridViewCellStyle1.Padding = new Padding(3, 2, 6, 2); + dataGridViewCellStyle1.Padding = new Padding(3, 1, 2, 1); ColumnIcon.DefaultCellStyle = dataGridViewCellStyle1; ColumnIcon.Frozen = true; ColumnIcon.HeaderText = "ColumnIcon"; diff --git a/UserInterface/Menu.cs b/UserInterface/Menu.cs index 7c80c9f..144de93 100644 --- a/UserInterface/Menu.cs +++ b/UserInterface/Menu.cs @@ -730,20 +730,17 @@ namespace SystemTrayMenu.UserInterface factor = Properties.Settings.Default.RowHeighteInPercentageTouch / 100f; } - double factorIconSizeInPercent = Properties.Settings.Default.IconSizeInPercent / 100f; - - if (factor < factorIconSizeInPercent) - { - factor = factorIconSizeInPercent; - } - if (menuPredecessor == null) { if (dgv.Tag == null && dgv.Rows.Count > 0) { - // Find row size based on content and apply factor - dgv.AutoResizeRows(); - dgv.RowTemplate.Height = (int)(dgv.Rows[0].Height * factor); + // dgv.AutoResizeRows(); slightly incorrect depending on dpi + // 100% = 20 instead 21 + // 125% = 23 instead 27, 150% = 28 instead 32 + // 175% = 33 instead 37, 200% = 35 instead 42 + // #418 use 21 as default and scale it manually + float rowHeightDefault = 21.24f * Scaling.FactorByDpi; + dgv.RowTemplate.Height = (int)((rowHeightDefault * factor * Scaling.Factor) + 0.5); dgv.Tag = true; } } diff --git a/UserInterface/SettingsForm.cs b/UserInterface/SettingsForm.cs index 2f161d6..7046982 100644 --- a/UserInterface/SettingsForm.cs +++ b/UserInterface/SettingsForm.cs @@ -1254,7 +1254,7 @@ namespace SystemTrayMenu.UserInterface private void ButtonSizeAndLocationDefault_Click(object sender, EventArgs e) { - numericUpDownSizeInPercent.Value = 125; + numericUpDownSizeInPercent.Value = 100; numericUpDownIconSizeInPercent.Value = 100; numericUpDownRowHeighteInPercentage.Value = 100; numericUpDownMenuWidth.Value = 400; diff --git a/Utilities/DataGridViewExtensions.cs b/Utilities/DataGridViewExtensions.cs index c358ef9..7f7f253 100644 --- a/Utilities/DataGridViewExtensions.cs +++ b/Utilities/DataGridViewExtensions.cs @@ -20,13 +20,13 @@ namespace SystemTrayMenu.Utilities /// datagridview. internal static void FastAutoSizeColumns(this DataGridView dgv) { - using Graphics gfx = dgv.CreateGraphics(); - gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; + using Graphics graphics = dgv.CreateGraphics(); + graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; float widthMax = WidthMin; DataTable data = (DataTable)dgv.DataSource; foreach (DataRow row in data.Rows) { - float checkWidth = gfx.MeasureString( + float checkWidth = graphics.MeasureString( ((RowData)row[2]).Text + "___", dgv.RowTemplate.DefaultCellStyle.Font).Width; if (checkWidth > widthMax) @@ -41,13 +41,11 @@ namespace SystemTrayMenu.Utilities } dgv.Columns[1].Width = (int)(widthMax + 0.5); - string stringWithWidthLikeIcon = "____"; - float width0 = gfx.MeasureString( - stringWithWidthLikeIcon, - dgv.RowTemplate.DefaultCellStyle.Font).Width; - double factorIconSizeInPercent = Properties.Settings.Default.IconSizeInPercent / 100f; - dgv.Columns[0].Width = (int)(width0 * factorIconSizeInPercent); + + // IcoWidth 100% = 21px, 175% is 33, +3+2 is padding from ColumnIcon + float icoWidth = (16 * Scaling.FactorByDpi) + 5; + dgv.Columns[0].Width = (int)((icoWidth * factorIconSizeInPercent * Scaling.Factor) + 0.5); } } } diff --git a/Utilities/File/IconReader.cs b/Utilities/File/IconReader.cs index e0ce73f..86cdbd4 100644 --- a/Utilities/File/IconReader.cs +++ b/Utilities/File/IconReader.cs @@ -88,7 +88,13 @@ namespace SystemTrayMenu.Utilities { loading = false; string extension = Path.GetExtension(path); - IconSize size = IconSize.Large; + IconSize size = IconSize.Small; + if (Scaling.Factor >= 1.25f || + Scaling.FactorByDpi >= 1.25f || + Properties.Settings.Default.IconSizeInPercent / 100f >= 1.25f) + { + size = IconSize.Large; + } string key = path; if (!string.IsNullOrEmpty(keyPath)) @@ -129,8 +135,9 @@ namespace SystemTrayMenu.Utilities loading = false; IconSize size = IconSize.Small; - if (Scaling.Factor >= 1.50f || - Properties.Settings.Default.IconSizeInPercent / 100f >= 1.50f) + if (Scaling.Factor >= 1.25f || + Scaling.FactorByDpi >= 1.25f || + Properties.Settings.Default.IconSizeInPercent / 100f >= 1.25f) { // IconSize.Large returns another folder icon than windows explorer size = IconSize.Large; diff --git a/Utilities/Scaling.cs b/Utilities/Scaling.cs index 016c1e7..ad900d9 100644 --- a/Utilities/Scaling.cs +++ b/Utilities/Scaling.cs @@ -5,25 +5,27 @@ namespace SystemTrayMenu.Utilities { using System; + using System.Drawing; internal static class Scaling { - private enum DeviceCap - { - VERTRES = 10, - DESKTOPVERTRES = 117, - } - public static float Factor { get; private set; } = 1; - internal static void Initialize() + public static float FactorByDpi { get; private set; } = 1; + + public static void Initialize() { Factor = Properties.Settings.Default.SizeInPercent / 100f; } - internal static int Scale(int width) + public static int Scale(int width) { return (int)Math.Round(width * Factor, 0, MidpointRounding.AwayFromZero); } + + public static void CalculateFactorByDpi(Graphics graphics) + { + FactorByDpi = graphics.DpiX / 96; + } } }