From bbaf82ba0c4bc50b13da72880ce344bcfcfce98a Mon Sep 17 00:00:00 2001 From: Gengar Date: Mon, 8 Jan 2024 17:02:38 -0600 Subject: [PATCH] Apply Theme to MainForm on ThemeChange. --- RaidCrawler.WinForms/MainWindow.cs | 12 +++++++++++- RaidCrawler.WinForms/SubForms/ConfigWindow.cs | 8 +++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/RaidCrawler.WinForms/MainWindow.cs b/RaidCrawler.WinForms/MainWindow.cs index bd5babd..a3b5668 100644 --- a/RaidCrawler.WinForms/MainWindow.cs +++ b/RaidCrawler.WinForms/MainWindow.cs @@ -147,6 +147,9 @@ private void ApplyTheme(string theme) SetDarkTheme(); else SetLightTheme(); + + this.Invalidate(); + this.Refresh(); } private void SetDarkTheme() { @@ -941,7 +944,14 @@ private void Seed_Click(object sender, EventArgs e) private void ConfigSettings_Click(object sender, EventArgs e) { var form = new ConfigWindow(Config); - ShowDialog(form); + form.ThemeChanged += OnThemeChanged; + form.ShowDialog(); + form.ThemeChanged -= OnThemeChanged; // Unsubscribe from the event + } + + private void OnThemeChanged(string newTheme) + { + ApplyTheme(newTheme); } private void EnableFilters_Click(object sender, EventArgs e) diff --git a/RaidCrawler.WinForms/SubForms/ConfigWindow.cs b/RaidCrawler.WinForms/SubForms/ConfigWindow.cs index f5326b8..cfd5920 100644 --- a/RaidCrawler.WinForms/SubForms/ConfigWindow.cs +++ b/RaidCrawler.WinForms/SubForms/ConfigWindow.cs @@ -5,6 +5,8 @@ namespace RaidCrawler.WinForms.SubForms; public partial class ConfigWindow : Form { private readonly ClientConfig c; + public delegate void ThemeChangedEventHandler(string newTheme); + public event ThemeChangedEventHandler ThemeChanged; public ConfigWindow(ClientConfig c) { @@ -110,9 +112,13 @@ private void ThemeComboBox_SelectedIndexChanged(object sender, EventArgs e) { this.SetLightTheme(); } + // Save the selected theme to the configuration - this.c.Theme = ThemeComboBox.SelectedItem.ToString(); + this.c.Theme = selectedTheme; // Use the variable you have defined SaveConfig(); + + // Invoke the ThemeChanged event with the correct variable + ThemeChanged?.Invoke(selectedTheme); } private void SaveConfig()