From 46746e7a86266ae731fbf00f5abcee979b66baf3 Mon Sep 17 00:00:00 2001 From: xmikedanielsx <38277241+xmikedanielsx@users.noreply.github.com> Date: Wed, 31 Jul 2024 03:54:10 -0400 Subject: [PATCH] Prevent Menu From Closing When Turning On or Off Sensors to Display (#1395) * Prevent Hardware Menu From Closing When Selecting Sensors To Turn Off * Fix Double Declaration of PSU Menu Item in Designer. Not allowing Designer to Load in VS * Remove Properties Resource File as it's auto generated. * Implemented @pedrosimoes79 suggestion. Work and much cleaner. Thank you. * Update MainForm.cs --------- Co-authored-by: PhyxionNL <7643972+PhyxionNL@users.noreply.github.com> --- LibreHardwareMonitor/UI/MainForm.Designer.cs | 15 +++++++-------- LibreHardwareMonitor/UI/MainForm.cs | 13 +++++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/LibreHardwareMonitor/UI/MainForm.Designer.cs b/LibreHardwareMonitor/UI/MainForm.Designer.cs index 18d0163..98e1ca9 100644 --- a/LibreHardwareMonitor/UI/MainForm.Designer.cs +++ b/LibreHardwareMonitor/UI/MainForm.Designer.cs @@ -51,7 +51,7 @@ namespace LibreHardwareMonitor.UI this.saveReportMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.MenuItem2 = new System.Windows.Forms.ToolStripSeparator(); this.resetMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.menuItem5 = new System.Windows.Forms.ToolStripMenuItem(); + this.menuItemFileHardware = new System.Windows.Forms.ToolStripMenuItem(); this.mainboardMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.cpuMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ramMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -139,7 +139,6 @@ namespace LibreHardwareMonitor.UI this.splitContainer = new LibreHardwareMonitor.UI.SplitContainerAdv(); this.treeView = new Aga.Controls.Tree.TreeViewAdv(); this.batteryMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.psuMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.backgroundUpdater = new System.ComponentModel.BackgroundWorker(); this.mainMenu.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); @@ -244,7 +243,7 @@ namespace LibreHardwareMonitor.UI this.saveReportMenuItem, this.MenuItem2, this.resetMenuItem, - this.menuItem5, + this.menuItemFileHardware, this.menuItem6, this.exitMenuItem}); this.fileMenuItem.Name = "fileMenuItem"; @@ -272,7 +271,7 @@ namespace LibreHardwareMonitor.UI // // menuItem5 // - this.menuItem5.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.menuItemFileHardware.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.mainboardMenuItem, this.cpuMenuItem, this.ramMenuItem, @@ -282,9 +281,9 @@ namespace LibreHardwareMonitor.UI this.nicMenuItem, this.psuMenuItem, this.batteryMenuItem}); - this.menuItem5.Name = "menuItem5"; - this.menuItem5.Size = new System.Drawing.Size(180, 22); - this.menuItem5.Text = "Hardware"; + this.menuItemFileHardware.Name = "menuItem5"; + this.menuItemFileHardware.Size = new System.Drawing.Size(180, 22); + this.menuItemFileHardware.Text = "Hardware"; // // mainboardMenuItem // @@ -1055,7 +1054,7 @@ namespace LibreHardwareMonitor.UI private System.Windows.Forms.ToolStripMenuItem webMenuItem; private System.Windows.Forms.ToolStripMenuItem runWebServerMenuItem; private System.Windows.Forms.ToolStripMenuItem serverPortMenuItem; - private System.Windows.Forms.ToolStripMenuItem menuItem5; + private System.Windows.Forms.ToolStripMenuItem menuItemFileHardware; private System.Windows.Forms.ToolStripMenuItem mainboardMenuItem; private System.Windows.Forms.ToolStripMenuItem cpuMenuItem; private System.Windows.Forms.ToolStripMenuItem gpuMenuItem; diff --git a/LibreHardwareMonitor/UI/MainForm.cs b/LibreHardwareMonitor/UI/MainForm.cs index 6e47b0d..1f71cc5 100644 --- a/LibreHardwareMonitor/UI/MainForm.cs +++ b/LibreHardwareMonitor/UI/MainForm.cs @@ -228,6 +228,11 @@ public sealed partial class MainForm : Form _readBatterySensors.Changed += delegate { _computer.IsBatteryEnabled = _readBatterySensors.Value; }; _showGadget = new UserOption("gadgetMenuItem", false, gadgetMenuItem, _settings); + + // Prevent Menu From Closing When UnClicking Hardware Items + menuItemFileHardware.DropDown.Closing += StopFileHardwareMenuFromClosing; + + _showGadget.Changed += delegate { if (_gadget != null) @@ -459,6 +464,14 @@ public sealed partial class MainForm : Form Microsoft.Win32.SystemEvents.PowerModeChanged += PowerModeChanged; } + private void StopFileHardwareMenuFromClosing(object sender, ToolStripDropDownClosingEventArgs e) + { + if (e.CloseReason == ToolStripDropDownCloseReason.ItemClicked) + { + e.Cancel = true; + } + } + public bool AuthWebServerMenuItemChecked { get { return authWebServerMenuItem.Checked; }