From 0b3e096ec6dd74878217e6237af5301248f37494 Mon Sep 17 00:00:00 2001 From: Markus Hofknecht Date: Wed, 6 May 2020 13:59:31 +0200 Subject: [PATCH] #49, #53, #55 0.9.2.27 --- Business/App.cs | 4 --- Business/Program.cs | 3 +++ Properties/AssemblyInfo.cs | 4 +-- UserInterface/Menu.cs | 15 +---------- UserInterface/SettingsForm.Designer.cs | 37 +++++++++++++++----------- Utilities/DataGridViewExtensions.cs | 8 ++++++ Utilities/File/IconReader.cs | 18 ++++++++++--- 7 files changed, 51 insertions(+), 38 deletions(-) diff --git a/Business/App.cs b/Business/App.cs index a11b658..1579c8f 100644 --- a/Business/App.cs +++ b/Business/App.cs @@ -16,15 +16,11 @@ namespace SystemTrayMenu public App() { - Scaling.Initialize(); - FolderOptions.Initialize(); - Screen screen = Screen.PrimaryScreen; Statics.ScreenHeight = screen.Bounds.Height; Statics.ScreenWidth = screen.Bounds.Width; Statics.ScreenRight = screen.Bounds.Right; Statics.TaskbarHeight = new WindowsTaskbar().Size.Height; - AppRestart.BeforeRestarting += Dispose; SystemEvents.DisplaySettingsChanged += AppRestart.ByDisplaySettings; menus.LoadStarted += menuNotifyIcon.LoadingStart; diff --git a/Business/Program.cs b/Business/Program.cs index 06f29a2..5a53ef7 100644 --- a/Business/Program.cs +++ b/Business/Program.cs @@ -28,6 +28,9 @@ namespace SystemTrayMenu AskUserSendError(t.Exception); } + Scaling.Initialize(); + FolderOptions.Initialize(); + using (new App()) { Log.WriteApplicationRuns(); diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index f59d622..0449fd5 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -35,5 +35,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("0.9.2.26")] -[assembly: AssemblyFileVersion("0.9.2.26")] +[assembly: AssemblyVersion("0.9.2.27")] +[assembly: AssemblyFileVersion("0.9.2.27")] diff --git a/UserInterface/Menu.cs b/UserInterface/Menu.cs index 954fdfa..bfad1ca 100644 --- a/UserInterface/Menu.cs +++ b/UserInterface/Menu.cs @@ -35,7 +35,6 @@ namespace SystemTrayMenu.UserInterface internal int Level = 0; private readonly Fading fading = new Fading(); - private bool autoResizeRowsDone = false; private bool isShowing = false; internal Menu() @@ -219,23 +218,11 @@ namespace SystemTrayMenu.UserInterface internal void AdjustSizeAndLocation(Menu menuPredecessor = null) { - if (!autoResizeRowsDone) - { - autoResizeRowsDone = true; - dgv.AutoResizeRows(); - } + dgv.AutoResizeRows(); int dgvHeightNeeded = dgv.Rows.GetRowsHeight( DataGridViewElementStates.None); - int labelTitleHeight = labelTitle.Height; - if (labelTitle.IsDisposed) - { - labelTitleHeight = 0; - } int menuRestNeeded = Height - dgv.Height; - //labelTitleHeight + tableLayoutPanelSearch.Height + - //(int)Math.Round(5 * Scaling.Factor); - //(tableLayoutPanelSearch.Margin.Vertical + 5) * Scaling.Factor); int dgvHeightMax = Statics.ScreenHeight - Statics.TaskbarHeight - menuRestNeeded; diff --git a/UserInterface/SettingsForm.Designer.cs b/UserInterface/SettingsForm.Designer.cs index bee9856..0020a6f 100644 --- a/UserInterface/SettingsForm.Designer.cs +++ b/UserInterface/SettingsForm.Designer.cs @@ -37,7 +37,6 @@ namespace SystemTrayMenu.UserInterface this.tableLayoutPanelGeneral = new System.Windows.Forms.TableLayoutPanel(); this.comboBoxLanguage = new System.Windows.Forms.ComboBox(); this.labelLanguage = new System.Windows.Forms.Label(); - this.textBoxHotkey = new SystemTrayMenu.UserInterface.Controls.HotkeyControl(); this.checkBoxAutostart = new System.Windows.Forms.CheckBox(); this.labelHotkey = new System.Windows.Forms.Label(); this.labelAutostart = new System.Windows.Forms.Label(); @@ -52,6 +51,7 @@ namespace SystemTrayMenu.UserInterface this.tableLayoutPanelBottom = new System.Windows.Forms.TableLayoutPanel(); this.buttonOk = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button(); + this.textBoxHotkey = new SystemTrayMenu.UserInterface.Controls.HotkeyControl(); this.tableLayoutPanelMain.SuspendLayout(); this.tabControl1.SuspendLayout(); this.tabPageGeneral.SuspendLayout(); @@ -146,20 +146,6 @@ namespace SystemTrayMenu.UserInterface this.labelLanguage.TabIndex = 2; this.labelLanguage.Text = "labelLanguage"; // - // textBoxHotkey - // - this.textBoxHotkey.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); - this.textBoxHotkey.Hotkey = System.Windows.Forms.Keys.None; - this.textBoxHotkey.HotkeyModifiers = System.Windows.Forms.Keys.None; - this.textBoxHotkey.Location = new System.Drawing.Point(92, 57); - this.textBoxHotkey.Margin = new System.Windows.Forms.Padding(9, 7, 9, 0); - this.textBoxHotkey.Name = "textBoxHotkey"; - this.textBoxHotkey.Size = new System.Drawing.Size(200, 20); - this.textBoxHotkey.TabIndex = 0; - this.textBoxHotkey.Text = "None"; - this.textBoxHotkey.Enter += new System.EventHandler(this.textBoxHotkey_Enter); - this.textBoxHotkey.Leave += new System.EventHandler(this.textBoxHotkey_Leave); - // // checkBoxAutostart // this.checkBoxAutostart.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); @@ -335,9 +321,12 @@ namespace SystemTrayMenu.UserInterface // // buttonOk // + this.buttonOk.AutoSize = true; + this.buttonOk.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.buttonOk.DialogResult = System.Windows.Forms.DialogResult.OK; this.buttonOk.Location = new System.Drawing.Point(236, 0); this.buttonOk.Margin = new System.Windows.Forms.Padding(3, 0, 3, 0); + this.buttonOk.MinimumSize = new System.Drawing.Size(75, 23); this.buttonOk.Name = "buttonOk"; this.buttonOk.Size = new System.Drawing.Size(75, 23); this.buttonOk.TabIndex = 2; @@ -347,9 +336,12 @@ namespace SystemTrayMenu.UserInterface // // buttonCancel // + this.buttonCancel.AutoSize = true; + this.buttonCancel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.buttonCancel.Location = new System.Drawing.Point(317, 0); this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 0, 3, 0); + this.buttonCancel.MinimumSize = new System.Drawing.Size(75, 23); this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.Size = new System.Drawing.Size(75, 23); this.buttonCancel.TabIndex = 3; @@ -357,6 +349,20 @@ namespace SystemTrayMenu.UserInterface this.buttonCancel.UseVisualStyleBackColor = true; this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); // + // textBoxHotkey + // + this.textBoxHotkey.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.textBoxHotkey.Hotkey = System.Windows.Forms.Keys.None; + this.textBoxHotkey.HotkeyModifiers = System.Windows.Forms.Keys.None; + this.textBoxHotkey.Location = new System.Drawing.Point(92, 57); + this.textBoxHotkey.Margin = new System.Windows.Forms.Padding(9, 7, 9, 0); + this.textBoxHotkey.Name = "textBoxHotkey"; + this.textBoxHotkey.Size = new System.Drawing.Size(200, 20); + this.textBoxHotkey.TabIndex = 0; + this.textBoxHotkey.Text = "None"; + this.textBoxHotkey.Enter += new System.EventHandler(this.textBoxHotkey_Enter); + this.textBoxHotkey.Leave += new System.EventHandler(this.textBoxHotkey_Leave); + // // SettingsForm // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); @@ -385,6 +391,7 @@ namespace SystemTrayMenu.UserInterface this.tableLayoutPanel5.ResumeLayout(false); this.tableLayoutPanel5.PerformLayout(); this.tableLayoutPanelBottom.ResumeLayout(false); + this.tableLayoutPanelBottom.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); diff --git a/Utilities/DataGridViewExtensions.cs b/Utilities/DataGridViewExtensions.cs index 33029d1..fc06e10 100644 --- a/Utilities/DataGridViewExtensions.cs +++ b/Utilities/DataGridViewExtensions.cs @@ -32,6 +32,14 @@ namespace SystemTrayMenu.Utilities } } dgv.Columns[i].Width = (int)(widthMax + 0.5); + + string stringWithWidthLikeIcon = "___"; +#pragma warning disable CA1303 // Do not pass literals as localized parameters + float Width0 = gfx.MeasureString(stringWithWidthLikeIcon, +#pragma warning restore CA1303 // Do not pass literals as localized parameters + dgv.RowTemplate.DefaultCellStyle.Font + ).Width * Scaling.Factor; + dgv.Columns[0].Width = (int)Width0; } } } diff --git a/Utilities/File/IconReader.cs b/Utilities/File/IconReader.cs index 5773b6b..bb55416 100644 --- a/Utilities/File/IconReader.cs +++ b/Utilities/File/IconReader.cs @@ -118,7 +118,17 @@ namespace SystemTrayMenu.Utilities hIcon = DllImports.NativeMethods.ImageList_GetIcon(hImageList, shfi.iIcon, DllImports.NativeMethods.IldTransparent); } - icon = (Icon)Icon.FromHandle(hIcon).Clone(); + try + { + // Copy (clone) the returned icon to a new object, thus allowing us to clean-up properly + icon = (Icon)Icon.FromHandle(hIcon).Clone(); + } +#pragma warning disable CA1031 // Do not catch general exception types + catch (Exception ex) +#pragma warning restore CA1031 // Do not catch general exception types + { + Log.Error($"filePath:'{filePath}'", ex); + } // Cleanup if (!linkOverlay) @@ -178,9 +188,11 @@ namespace SystemTrayMenu.Utilities icon = (Icon)Icon.FromHandle(shfi.hIcon).Clone(); DllImports.NativeMethods.User32DestroyIcon(shfi.hIcon); } - catch +#pragma warning disable CA1031 // Do not catch general exception types + catch (Exception ex) +#pragma warning restore CA1031 // Do not catch general exception types { -#warning todo + Log.Error($"directoryPath:'{directoryPath}'", ex); } }