From 08dde604e3ec8247ba33a6484ebaed59f62ee664 Mon Sep 17 00:00:00 2001 From: CodingWonders <101426328+CodingWonders@users.noreply.github.com> Date: Sat, 21 Sep 2024 19:42:48 +0200 Subject: [PATCH] [AppEvent] Handle color scheme changes seamlessly --- ApplicationEvents.vb | 10 ++++++++++ MainForm.vb | 34 ---------------------------------- 2 files changed, 10 insertions(+), 34 deletions(-) diff --git a/ApplicationEvents.vb b/ApplicationEvents.vb index 1e844415..944b72e8 100644 --- a/ApplicationEvents.vb +++ b/ApplicationEvents.vb @@ -15,6 +15,9 @@ Namespace My ' NetworkAvailabilityChanged: se desencadena cuando la conexión de red está conectada o desconectada. Partial Friend Class MyApplication + Private lastThemeChangeTime As DateTime = DateTime.Now + Private debounceInterval As TimeSpan = TimeSpan.FromSeconds(2) + Private Sub Start(sender As Object, e As EventArgs) Handles Me.Startup AddHandler Microsoft.Win32.SystemEvents.UserPreferenceChanged, AddressOf SysEvts_UserPreferenceChanged AddHandler Microsoft.Win32.SystemEvents.DisplaySettingsChanging, AddressOf SysEvts_DisplaySettingsChanging @@ -90,6 +93,13 @@ Namespace My Private Sub SysEvts_UserPreferenceChanged(sender As Object, e As Microsoft.Win32.UserPreferenceChangedEventArgs) Debug.WriteLine(Date.UtcNow & " UTC - User Preference Category: " & e.Category.ToString()) + If e.Category = UserPreferenceCategory.General And DISMTools.MainForm.ColorMode = 0 Then + Dim currentTime As DateTime = DateTime.Now + If currentTime - lastThemeChangeTime > debounceInterval Then + DISMTools.MainForm.ChangePrgColors(0) + lastThemeChangeTime = currentTime + End If + End If End Sub Private Sub SysEvts_DisplaySettingsChanged(sender As Object, e As EventArgs) diff --git a/MainForm.vb b/MainForm.vb index 1bd81659..d56b0280 100644 --- a/MainForm.vb +++ b/MainForm.vb @@ -13948,40 +13948,6 @@ Public Class MainForm End If End Sub - Private Sub MainForm_SizeChanged(sender As Object, e As EventArgs) Handles MyBase.SizeChanged - If WindowState <> FormWindowState.Maximized Then - WndWidth = Width - WndHeight = Height - End If - If Visible And ColorMode = 0 Then - ChangePrgColors(0) - End If - If GroupBox1.Left < 0 Then - SplitPanels.SplitterDistance = 264 - End If - If BGProcNotify.Visible Then - If Environment.OSVersion.Version.Major = 10 Then ' The Left property also includes the window shadows on Windows 10 and 11 - BGProcNotify.Location = New Point(Left + 8, Top + StatusStrip.Top - (7 + StatusStrip.Height)) - ElseIf Environment.OSVersion.Version.Major = 6 Then - If Environment.OSVersion.Version.Minor = 1 Then ' The same also applies to Windows 7 - BGProcNotify.Location = New Point(Left + 8, Top + StatusStrip.Top - (7 + StatusStrip.Height)) - Else - BGProcNotify.Location = New Point(Left + 8, Top + StatusStrip.Top - StatusStrip.Height - 7) - End If - End If - ElseIf BGProcDetails.Visible And pinState = 0 Then - If Environment.OSVersion.Version.Major = 10 Then ' The Left property also includes the window shadows on Windows 10 and 11 - BGProcDetails.Location = New Point(Left + 8, Top + StatusStrip.Top - (75 + StatusStrip.Height)) - ElseIf Environment.OSVersion.Version.Major = 6 Then - If Environment.OSVersion.Version.Minor = 1 Then ' The same also applies to Windows 7 - BGProcDetails.Location = New Point(Left + 8, Top + StatusStrip.Top - (75 + StatusStrip.Height)) - Else - BGProcDetails.Location = New Point(Left + 8, Top + StatusStrip.Top - StatusStrip.Height - 75) - End If - End If - End If - End Sub - Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click If Not ProgressPanel.IsDisposed Then ProgressPanel.Dispose() imgCommitOperation = 0