Skip to content

Commit

Permalink
[AppEvent] Handle color scheme changes seamlessly
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingWonders committed Sep 21, 2024
1 parent 3594c2f commit 08dde60
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 34 deletions.
10 changes: 10 additions & 0 deletions ApplicationEvents.vb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
34 changes: 0 additions & 34 deletions MainForm.vb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 08dde60

Please sign in to comment.