From ac93c8418f98253efafb43c29061189a4f21fdd7 Mon Sep 17 00:00:00 2001 From: zsyg <3872006562@qq.com> Date: Mon, 30 Jun 2025 20:25:25 +0800 Subject: [PATCH] Add files via upload --- DownloadItem.cs | 35 +++++++++++- SettingsForm.cs | 141 ++++++++++++++++++++++++++++++------------------ 2 files changed, 122 insertions(+), 54 deletions(-) diff --git a/DownloadItem.cs b/DownloadItem.cs index 6882f11..0729c59 100644 --- a/DownloadItem.cs +++ b/DownloadItem.cs @@ -23,13 +23,40 @@ namespace AppStore cancelBtn = new Button(); InitializeComponent(); + + // 监听主题变化 + ThemeManager.ThemeChanged += (theme) => { + this.Invoke((MethodInvoker)delegate { + ApplyTheme(); + }); + }; + } + + private void ApplyTheme() + { + this.BackColor = ThemeManager.CurrentTheme == ThemeManager.ThemeMode.Light + ? Color.White + : Color.Black; + this.ForeColor = ThemeManager.CurrentTheme == ThemeManager.ThemeMode.Light + ? Color.Black + : Color.White; + + cancelBtn.BackColor = ThemeManager.CurrentTheme == ThemeManager.ThemeMode.Light + ? SystemColors.Control + : Color.FromArgb(70, 70, 70); + cancelBtn.ForeColor = ThemeManager.TextColor; } private void InitializeComponent() { this.Size = new Size(400, 60); - this.BackColor = Color.White; + this.BackColor = ThemeManager.CurrentTheme == ThemeManager.ThemeMode.Light + ? Color.White + : Color.Black; this.BorderStyle = BorderStyle.FixedSingle; + this.ForeColor = ThemeManager.CurrentTheme == ThemeManager.ThemeMode.Light + ? Color.Black + : Color.White; // 文件名标签 nameLabel = new Label(); @@ -56,6 +83,12 @@ namespace AppStore cancelBtn.Text = "取消"; cancelBtn.Size = new Size(60, 25); cancelBtn.Location = new Point(320, 30); + cancelBtn.BackColor = ThemeManager.CurrentTheme == ThemeManager.ThemeMode.Light + ? SystemColors.Control + : Color.FromArgb(70, 70, 70); + cancelBtn.ForeColor = ThemeManager.TextColor; + cancelBtn.FlatStyle = FlatStyle.Flat; + cancelBtn.FlatAppearance.BorderSize = 0; cancelBtn.Click += CancelBtn_Click; this.Controls.Add(cancelBtn); } diff --git a/SettingsForm.cs b/SettingsForm.cs index e5588f6..5f06260 100644 --- a/SettingsForm.cs +++ b/SettingsForm.cs @@ -1,53 +1,88 @@ -using System; -using System.Diagnostics; -using System.IO; -using System.Windows.Forms; - -namespace AppStore -{ - public class SettingsUserControl : UserControl - { - private Button btnCleanLogs; - - public SettingsUserControl() - { - this.Dock = DockStyle.Fill; - this.BackColor = Color.White; - - // 设置顶部内边距 - this.Padding = new Padding(0, 30, 0, 0); - - btnCleanLogs = new Button(); - btnCleanLogs.Text = "清理日志"; - btnCleanLogs.Size = new Size(150, 40); - btnCleanLogs.Location = new Point((this.Width - 150) / 2, 50); // 调整Y坐标为50靠近顶部 - btnCleanLogs.Font = new Font("Microsoft YaHei", 10); - btnCleanLogs.Anchor = AnchorStyles.Top; // 添加顶部锚点 - btnCleanLogs.Click += (s, e) => CleanLogs(); - this.Controls.Add(btnCleanLogs); - } - - private void CleanLogs() - { - try - { - string logCleanerPath = Path.Combine("resource", "log_cleaner.exe"); - - if (File.Exists(logCleanerPath)) - { - Process.Start(logCleanerPath); - MessageBox.Show("日志清理程序已启动", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - else - { - MessageBox.Show("日志清理程序未找到", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - catch (Exception ex) - { - Logger.LogError("清理日志时出错", ex); - MessageBox.Show($"清理日志时出错: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } -} +using System; +using System.Diagnostics; +using System.IO; +using System.Windows.Forms; +using System.Drawing; + +namespace AppStore +{ + public class SettingsUserControl : UserControl + { + private Button btnCleanLogs; + private Button btnLightTheme; + private Button btnDarkTheme; + + public SettingsUserControl() + { + this.Dock = DockStyle.Fill; + ThemeManager.ApplyTheme(this); + + // 设置顶部内边距 + this.Padding = new Padding(0, 30, 0, 0); + + // 主题切换按钮 + btnLightTheme = new Button(); + btnLightTheme.Text = "浅色模式"; + btnLightTheme.Size = new Size(150, 40); + btnLightTheme.Location = new Point((this.Width - 320) / 2, 50); + btnLightTheme.Font = new Font("Microsoft YaHei", 10); + btnLightTheme.Anchor = AnchorStyles.Top; + btnLightTheme.Click += (s, e) => SwitchTheme(ThemeManager.ThemeMode.Light); + this.Controls.Add(btnLightTheme); + + btnDarkTheme = new Button(); + btnDarkTheme.Text = "深色模式"; + btnDarkTheme.Size = new Size(150, 40); + btnDarkTheme.Location = new Point(btnLightTheme.Right + 20, 50); + btnDarkTheme.Font = new Font("Microsoft YaHei", 10); + btnDarkTheme.Anchor = AnchorStyles.Top; + btnDarkTheme.Click += (s, e) => SwitchTheme(ThemeManager.ThemeMode.Dark); + this.Controls.Add(btnDarkTheme); + + // 清理日志按钮 + btnCleanLogs = new Button(); + btnCleanLogs.Text = "清理日志"; + btnCleanLogs.Size = new Size(150, 40); + btnCleanLogs.Location = new Point((this.Width - 150) / 2, 110); + btnCleanLogs.Font = new Font("Microsoft YaHei", 10); + btnCleanLogs.Anchor = AnchorStyles.Top; + btnCleanLogs.Click += (s, e) => CleanLogs(); + this.Controls.Add(btnCleanLogs); + + ThemeManager.ThemeChanged += OnThemeChanged; + } + + private void SwitchTheme(ThemeManager.ThemeMode theme) + { + ThemeManager.CurrentTheme = theme; + } + + private void OnThemeChanged(ThemeManager.ThemeMode theme) + { + ThemeManager.ApplyTheme(this); + } + + private void CleanLogs() + { + try + { + string logCleanerPath = Path.Combine("resource", "log_cleaner.exe"); + + if (File.Exists(logCleanerPath)) + { + Process.Start(logCleanerPath); + MessageBox.Show("日志清理程序已启动", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("日志清理程序未找到", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + catch (Exception ex) + { + Logger.LogError("清理日志时出错", ex); + MessageBox.Show($"清理日志时出错: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +}