Add files via upload

This commit is contained in:
zsyg
2025-06-30 20:25:25 +08:00
committed by GitHub
parent 5a49714ed7
commit ac93c8418f
2 changed files with 122 additions and 54 deletions

View File

@@ -23,13 +23,40 @@ namespace AppStore
cancelBtn = new Button(); cancelBtn = new Button();
InitializeComponent(); 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() private void InitializeComponent()
{ {
this.Size = new Size(400, 60); 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.BorderStyle = BorderStyle.FixedSingle;
this.ForeColor = ThemeManager.CurrentTheme == ThemeManager.ThemeMode.Light
? Color.Black
: Color.White;
// 文件名标签 // 文件名标签
nameLabel = new Label(); nameLabel = new Label();
@@ -56,6 +83,12 @@ namespace AppStore
cancelBtn.Text = "取消"; cancelBtn.Text = "取消";
cancelBtn.Size = new Size(60, 25); cancelBtn.Size = new Size(60, 25);
cancelBtn.Location = new Point(320, 30); 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; cancelBtn.Click += CancelBtn_Click;
this.Controls.Add(cancelBtn); this.Controls.Add(cancelBtn);
} }

View File

@@ -1,53 +1,88 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Windows.Forms; using System.Windows.Forms;
using System.Drawing;
namespace AppStore
{ namespace AppStore
public class SettingsUserControl : UserControl {
{ public class SettingsUserControl : UserControl
private Button btnCleanLogs; {
private Button btnCleanLogs;
public SettingsUserControl() private Button btnLightTheme;
{ private Button btnDarkTheme;
this.Dock = DockStyle.Fill;
this.BackColor = Color.White; public SettingsUserControl()
{
// 设置顶部内边距 this.Dock = DockStyle.Fill;
this.Padding = new Padding(0, 30, 0, 0); ThemeManager.ApplyTheme(this);
btnCleanLogs = new Button(); // 设置顶部内边距
btnCleanLogs.Text = "清理日志"; this.Padding = new Padding(0, 30, 0, 0);
btnCleanLogs.Size = new Size(150, 40);
btnCleanLogs.Location = new Point((this.Width - 150) / 2, 50); // 调整Y坐标为50靠近顶部 // 主题切换按钮
btnCleanLogs.Font = new Font("Microsoft YaHei", 10); btnLightTheme = new Button();
btnCleanLogs.Anchor = AnchorStyles.Top; // 添加顶部锚点 btnLightTheme.Text = "浅色模式";
btnCleanLogs.Click += (s, e) => CleanLogs(); btnLightTheme.Size = new Size(150, 40);
this.Controls.Add(btnCleanLogs); btnLightTheme.Location = new Point((this.Width - 320) / 2, 50);
} btnLightTheme.Font = new Font("Microsoft YaHei", 10);
btnLightTheme.Anchor = AnchorStyles.Top;
private void CleanLogs() btnLightTheme.Click += (s, e) => SwitchTheme(ThemeManager.ThemeMode.Light);
{ this.Controls.Add(btnLightTheme);
try
{ btnDarkTheme = new Button();
string logCleanerPath = Path.Combine("resource", "log_cleaner.exe"); btnDarkTheme.Text = "深色模式";
btnDarkTheme.Size = new Size(150, 40);
if (File.Exists(logCleanerPath)) btnDarkTheme.Location = new Point(btnLightTheme.Right + 20, 50);
{ btnDarkTheme.Font = new Font("Microsoft YaHei", 10);
Process.Start(logCleanerPath); btnDarkTheme.Anchor = AnchorStyles.Top;
MessageBox.Show("日志清理程序已启动", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); btnDarkTheme.Click += (s, e) => SwitchTheme(ThemeManager.ThemeMode.Dark);
} this.Controls.Add(btnDarkTheme);
else
{ // 清理日志按钮
MessageBox.Show("日志清理程序未找到", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); btnCleanLogs = new Button();
} btnCleanLogs.Text = "清理日志";
} btnCleanLogs.Size = new Size(150, 40);
catch (Exception ex) btnCleanLogs.Location = new Point((this.Width - 150) / 2, 110);
{ btnCleanLogs.Font = new Font("Microsoft YaHei", 10);
Logger.LogError("清理日志时出错", ex); btnCleanLogs.Anchor = AnchorStyles.Top;
MessageBox.Show($"清理日志时出错: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); 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);
}
}
}
}