Compare commits

...

6 Commits

Author SHA1 Message Date
zsyg
f7250dae08 修复主题系统带来的颜色 2025-07-01 10:26:26 +08:00
zsyg
ac93c8418f Add files via upload 2025-06-30 20:25:25 +08:00
zsyg
5a49714ed7 Add files via upload 2025-06-30 20:22:07 +08:00
zsyg
19056a1a8c Add files via upload 2025-06-30 20:21:19 +08:00
zsyg
7c4250f912 Add files via upload 2025-06-30 20:20:48 +08:00
zsyg
d056c24a1b Add files via upload 2025-06-30 20:20:21 +08:00
9 changed files with 1913 additions and 1563 deletions

View File

@@ -1,141 +1,144 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
namespace AppStore namespace AppStore
{ {
public class AboutUserControl : UserControl public class AboutUserControl : UserControl
{ {
private PictureBox logo = null!; private PictureBox logo = null!;
private Label infoLabel = null!; private Label infoLabel = null!;
public AboutUserControl() public AboutUserControl()
{ {
InitializeComponent(); InitializeComponent();
} }
private void InitializeComponent() private void InitializeComponent()
{ {
this.Dock = DockStyle.Fill; this.Dock = DockStyle.Fill;
this.BackColor = Color.White; this.BackColor = ThemeManager.BackgroundColor;
this.Padding = new Padding(20); this.Padding = new Padding(20);
// 创建主布局面板 // 创建主布局面板
TableLayoutPanel mainLayout = new TableLayoutPanel(); TableLayoutPanel mainLayout = new TableLayoutPanel();
mainLayout.Dock = DockStyle.Fill; mainLayout.Dock = DockStyle.Fill;
mainLayout.ColumnCount = 1; mainLayout.BackColor = ThemeManager.BackgroundColor;
mainLayout.RowCount = 2; mainLayout.ColumnCount = 1;
mainLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); mainLayout.RowCount = 2;
mainLayout.RowStyles.Add(new RowStyle(SizeType.AutoSize)); mainLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
mainLayout.RowStyles.Add(new RowStyle(SizeType.AutoSize)); mainLayout.RowStyles.Add(new RowStyle(SizeType.AutoSize));
mainLayout.Padding = new Padding(0, 20, 0, 20); mainLayout.RowStyles.Add(new RowStyle(SizeType.AutoSize));
mainLayout.Padding = new Padding(0, 20, 0, 20);
// 初始化并添加应用图标
logo = new PictureBox(); // 初始化并添加应用图标
try logo = new PictureBox();
{ try
logo.Image = Image.FromFile("img/png/kortapp-z.png"); {
} logo.Image = Image.FromFile("img/png/kortapp-z.png");
catch (Exception ex) }
{ catch (Exception ex)
Logger.LogError($"无法加载应用图标: {ex.Message}"); {
logo.Image = SystemIcons.Application.ToBitmap(); Logger.LogError($"无法加载应用图标: {ex.Message}");
} logo.Image = SystemIcons.Application.ToBitmap();
logo.SizeMode = PictureBoxSizeMode.Zoom; }
logo.Width = 200; logo.SizeMode = PictureBoxSizeMode.Zoom;
logo.Height = 200; logo.Width = 200;
logo.Anchor = AnchorStyles.None; logo.Height = 200;
logo.Margin = new Padding(0, 0, 0, 20); logo.Anchor = AnchorStyles.None;
mainLayout.Controls.Add(logo, 0, 0); logo.Margin = new Padding(0, 0, 0, 20);
mainLayout.Controls.Add(logo, 0, 0);
// 初始化并添加应用信息
infoLabel = new Label(); // 初始化并添加应用信息
infoLabel.Text = "kortapp-z\n版本: 1.1.0\n作者: zs-yg\n一个简单、开源的应用商店\nkortapp-z是完全免费\n基于.NET8和C/C++的软件"; infoLabel = new Label();
infoLabel.Font = new Font("Microsoft YaHei", 12); infoLabel.Text = "kortapp-z\n版本: 1.1.1\n作者: zs-yg\n一个简单、开源的应用商店\nkortapp-z是完全免费\n基于.NET8和C/C++的软件";
infoLabel.AutoSize = false; infoLabel.Font = new Font("Microsoft YaHei", 12);
infoLabel.Width = 300; infoLabel.AutoSize = false;
infoLabel.Height = 130; // 增加高度确保文字完整显示 infoLabel.Width = 300;
infoLabel.TextAlign = ContentAlignment.MiddleCenter; infoLabel.Height = 130; // 增加高度确保文字完整显示
infoLabel.Anchor = AnchorStyles.None; infoLabel.TextAlign = ContentAlignment.MiddleCenter;
mainLayout.Controls.Add(infoLabel, 0, 1); infoLabel.Anchor = AnchorStyles.None;
mainLayout.Controls.Add(infoLabel, 0, 1);
// 调整主布局为3行
mainLayout.RowCount = 3; // 调整主布局为3行
mainLayout.RowStyles.Add(new RowStyle(SizeType.AutoSize)); mainLayout.RowCount = 3;
mainLayout.RowStyles.Add(new RowStyle(SizeType.AutoSize)); mainLayout.RowStyles.Add(new RowStyle(SizeType.AutoSize));
mainLayout.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); mainLayout.RowStyles.Add(new RowStyle(SizeType.AutoSize));
mainLayout.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
// 在底部添加GitHub链接区域
TableLayoutPanel githubPanel = new TableLayoutPanel(); // 在底部添加GitHub链接区域
githubPanel.Dock = DockStyle.Bottom; TableLayoutPanel githubPanel = new TableLayoutPanel();
githubPanel.Height = 60; githubPanel.Dock = DockStyle.Bottom;
githubPanel.ColumnCount = 3; githubPanel.BackColor = ThemeManager.BackgroundColor;
githubPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); githubPanel.Height = 60;
githubPanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); githubPanel.ColumnCount = 3;
githubPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); githubPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
githubPanel.RowCount = 1; githubPanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
githubPanel.Padding = new Padding(10); githubPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
githubPanel.RowCount = 1;
// 添加GitHub图标 githubPanel.Padding = new Padding(10);
PictureBox githubIcon = new PictureBox();
try // 添加GitHub图标
{ PictureBox githubIcon = new PictureBox();
githubIcon.Image = Image.FromFile("img/jpg/github.jpg"); try
} {
catch (Exception ex) githubIcon.Image = Image.FromFile("img/jpg/github.jpg");
{ }
Logger.LogError($"无法加载GitHub图标: {ex.Message}"); catch (Exception ex)
githubIcon.Image = SystemIcons.Application.ToBitmap(); {
} Logger.LogError($"无法加载GitHub图标: {ex.Message}");
githubIcon.SizeMode = PictureBoxSizeMode.Zoom; githubIcon.Image = SystemIcons.Application.ToBitmap();
githubIcon.Width = 30; }
githubIcon.Height = 30; githubIcon.SizeMode = PictureBoxSizeMode.Zoom;
githubIcon.Cursor = Cursors.Hand; githubIcon.Width = 30;
githubIcon.Click += (s, e) => { githubIcon.Height = 30;
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo githubIcon.Cursor = Cursors.Hand;
{ githubIcon.Click += (s, e) => {
FileName = "https://github.com/zs-yg/kortapp-z", System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
UseShellExecute = true {
}); FileName = "https://github.com/zs-yg/kortapp-z",
}; UseShellExecute = true
});
// 添加文字说明 };
Label githubLabel = new Label();
githubLabel.Text = "🤗🤗🤗开源地址 🌟 欢迎点star和提交pr 🚀"; // 添加文字说明
githubLabel.Font = new Font("Microsoft YaHei", 10); Label githubLabel = new Label();
githubLabel.AutoSize = true; githubLabel.Text = "🤗🤗🤗开源地址 🌟 欢迎点star和提交pr 🚀";
githubLabel.Margin = new Padding(10, 0, 0, 0); githubLabel.Font = new Font("Microsoft YaHei", 10);
githubLabel.AutoSize = true;
// 创建包含图标和文字的面板 githubLabel.Margin = new Padding(10, 0, 0, 0);
Panel linkPanel = new Panel();
linkPanel.AutoSize = true; // 创建包含图标和文字的面板
linkPanel.Controls.Add(githubIcon); Panel linkPanel = new Panel();
linkPanel.Controls.Add(githubLabel); linkPanel.AutoSize = true;
githubIcon.Location = new Point(0, 0); linkPanel.BackColor = ThemeManager.BackgroundColor;
githubLabel.Location = new Point(githubIcon.Width + 10, 5); linkPanel.Controls.Add(githubIcon);
linkPanel.Controls.Add(githubLabel);
// 将链接面板添加到中间列 githubIcon.Location = new Point(0, 0);
githubPanel.Controls.Add(linkPanel, 1, 0); githubLabel.Location = new Point(githubIcon.Width + 10, 5);
this.Controls.Add(mainLayout); // 将链接面板添加到中间列
this.Controls.Add(githubPanel); githubPanel.Controls.Add(linkPanel, 1, 0);
}
} this.Controls.Add(mainLayout);
this.Controls.Add(githubPanel);
// 保留原AboutForm作为容器(可选) }
public class AboutForm : Form }
{
public AboutForm() // 保留原AboutForm作为容器(可选)
{ public class AboutForm : Form
this.Text = "关于 kortapp-z"; {
this.Size = new Size(500, 400); public AboutForm()
this.StartPosition = FormStartPosition.CenterScreen; {
this.FormBorderStyle = FormBorderStyle.FixedDialog; this.Text = "关于 kortapp-z";
this.MaximizeBox = false; this.Size = new Size(500, 400);
this.MinimizeBox = false; this.StartPosition = FormStartPosition.CenterScreen;
this.FormBorderStyle = FormBorderStyle.FixedDialog;
var aboutControl = new AboutUserControl(); this.MaximizeBox = false;
this.Controls.Add(aboutControl); this.MinimizeBox = false;
}
} var aboutControl = new AboutUserControl();
} this.Controls.Add(aboutControl);
}
}
}

View File

@@ -13,7 +13,9 @@ namespace AppStore
{ {
private PictureBox iconBox; private PictureBox iconBox;
private Label nameLabel; private Label nameLabel;
private Panel namePanel;
private Button downloadBtn; private Button downloadBtn;
private Color borderColor = SystemColors.ControlDark;
private static readonly ConcurrentDictionary<string, System.Drawing.Drawing2D.GraphicsPath> PathCache = private static readonly ConcurrentDictionary<string, System.Drawing.Drawing2D.GraphicsPath> PathCache =
new ConcurrentDictionary<string, System.Drawing.Drawing2D.GraphicsPath>(); new ConcurrentDictionary<string, System.Drawing.Drawing2D.GraphicsPath>();
@@ -27,6 +29,7 @@ namespace AppStore
// 确保关键对象不为null // 确保关键对象不为null
iconBox = new PictureBox() { SizeMode = PictureBoxSizeMode.StretchImage }; iconBox = new PictureBox() { SizeMode = PictureBoxSizeMode.StretchImage };
nameLabel = new Label() { Text = string.Empty }; nameLabel = new Label() { Text = string.Empty };
namePanel = new Panel();
downloadBtn = new Button() { Text = "下载" }; downloadBtn = new Button() { Text = "下载" };
// 确保DownloadManager已初始化 // 确保DownloadManager已初始化
@@ -57,14 +60,29 @@ namespace AppStore
iconBox.SizeMode = PictureBoxSizeMode.StretchImage; iconBox.SizeMode = PictureBoxSizeMode.StretchImage;
this.Controls.Add(iconBox); this.Controls.Add(iconBox);
// 应用名称 // 应用名称 - 使用Panel包裹Label实现边框颜色
// namePanel已在构造函数中初始化
namePanel.Size = new Size(Width - 20, 40);
namePanel.Location = new Point(10, 100);
namePanel.Paint += (sender, e) => {
ControlPaint.DrawBorder(e.Graphics, namePanel.ClientRectangle,
borderColor, ButtonBorderStyle.Solid);
};
nameLabel = new Label(); nameLabel = new Label();
nameLabel.AutoSize = false; nameLabel.Dock = DockStyle.Fill;
nameLabel.Size = new Size(Width - 20, 40);
nameLabel.Location = new Point(10, 100);
nameLabel.Font = new Font("Microsoft YaHei", 10, FontStyle.Bold); nameLabel.Font = new Font("Microsoft YaHei", 10, FontStyle.Bold);
nameLabel.TextAlign = ContentAlignment.MiddleCenter; nameLabel.TextAlign = ContentAlignment.MiddleCenter;
this.Controls.Add(nameLabel);
namePanel.Controls.Add(nameLabel);
// 初始主题设置
UpdateLabelTheme();
// 订阅主题变化事件
ThemeManager.ThemeChanged += (theme) => UpdateLabelTheme();
this.Controls.Add(namePanel);
// 下载按钮 // 下载按钮
downloadBtn = new Button(); downloadBtn = new Button();
@@ -92,6 +110,25 @@ namespace AppStore
downloadBtn.Visible = ShowDownloadButton; downloadBtn.Visible = ShowDownloadButton;
} }
private void UpdateLabelTheme()
{
if (ThemeManager.CurrentTheme == ThemeManager.ThemeMode.Dark)
{
nameLabel.BackColor = Color.Black;
nameLabel.ForeColor = Color.White;
namePanel.BackColor = Color.Black;
borderColor = Color.White;
}
else
{
nameLabel.BackColor = Color.White;
nameLabel.ForeColor = Color.Black;
namePanel.BackColor = Color.White;
borderColor = SystemColors.ControlDark;
}
namePanel.Invalidate(); // 触发重绘
}
/// <summary> /// <summary>
/// 初始化卡片边框路径 /// 初始化卡片边框路径
/// 使用C++程序计算高性能边框路径并缓存结果 /// 使用C++程序计算高性能边框路径并缓存结果

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);
} }

File diff suppressed because it is too large Load Diff

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);
}
}
}
}

127
ThemeManager.cs Normal file
View File

@@ -0,0 +1,127 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Text.Json;
using System.IO;
namespace AppStore
{
public static class ThemeManager
{
public enum ThemeMode
{
Light,
Dark
}
private static readonly string ThemeConfigPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"zsyg", "kortapp-z", ".date", "theme.json");
private static ThemeMode _currentTheme = LoadTheme();
private static ThemeMode LoadTheme()
{
try
{
if (File.Exists(ThemeConfigPath))
{
var json = File.ReadAllText(ThemeConfigPath);
return JsonSerializer.Deserialize<ThemeMode>(json);
}
}
catch
{
// 忽略错误,使用默认主题
}
return ThemeMode.Light;
}
private static void SaveTheme(ThemeMode theme)
{
try
{
var dir = Path.GetDirectoryName(ThemeConfigPath);
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
var json = JsonSerializer.Serialize(theme);
File.WriteAllText(ThemeConfigPath, json);
}
catch
{
// 忽略错误
}
}
// 浅色主题颜色
private static readonly Color LightBackground = Color.FromArgb(255, 255, 255);
private static readonly Color LightControlBackground = Color.FromArgb(240, 240, 240);
private static readonly Color LightText = Color.FromArgb(30, 30, 30);
private static readonly Color LightButtonHover = Color.FromArgb(230, 230, 230);
private static readonly Color LightButtonActive = Color.FromArgb(220, 220, 220);
// 深色主题颜色
private static readonly Color DarkBackground = Color.FromArgb(30, 30, 30);
private static readonly Color DarkControlBackground = Color.FromArgb(45, 45, 45);
private static readonly Color DarkText = Color.FromArgb(240, 240, 240);
private static readonly Color DarkButtonHover = Color.FromArgb(60, 60, 60);
private static readonly Color DarkButtonActive = Color.FromArgb(70, 70, 70);
public static event Action<ThemeMode> ThemeChanged = delegate {};
public static ThemeMode CurrentTheme
{
get => _currentTheme;
set
{
if (_currentTheme != value)
{
_currentTheme = value;
ThemeChanged?.Invoke(value);
SaveTheme(value);
}
}
}
public static Color BackgroundColor =>
_currentTheme == ThemeMode.Light ? LightBackground : DarkBackground;
public static Color ControlBackgroundColor =>
_currentTheme == ThemeMode.Light ? LightControlBackground : DarkControlBackground;
public static Color TextColor =>
_currentTheme == ThemeMode.Light ? LightText : DarkText;
public static Color ButtonHoverColor =>
_currentTheme == ThemeMode.Light ? LightButtonHover : DarkButtonHover;
public static Color ButtonActiveColor =>
_currentTheme == ThemeMode.Light ? LightButtonActive : DarkButtonActive;
public static void ApplyTheme(Control control)
{
ApplyThemeToControl(control);
}
private static void ApplyThemeToControl(Control control)
{
control.BackColor = BackgroundColor;
control.ForeColor = TextColor;
if (control is Button button)
{
button.FlatStyle = FlatStyle.Flat;
button.FlatAppearance.BorderSize = 0;
button.FlatAppearance.MouseOverBackColor = ButtonHoverColor;
button.FlatAppearance.MouseDownBackColor = ButtonActiveColor;
}
foreach (Control childControl in control.Controls)
{
ApplyThemeToControl(childControl);
}
}
}
}

View File

@@ -8,6 +8,8 @@ namespace AppStore
{ {
private PictureBox iconBox = new PictureBox(); private PictureBox iconBox = new PictureBox();
private Label nameLabel = new Label(); private Label nameLabel = new Label();
private Panel namePanel = new Panel();
private Color borderColor = SystemColors.ControlDark;
public string ToolName { get; set; } = string.Empty; public string ToolName { get; set; } = string.Empty;
public Image ToolIcon { get; set; } = SystemIcons.Shield.ToBitmap(); public Image ToolIcon { get; set; } = SystemIcons.Shield.ToBitmap();
@@ -37,14 +39,28 @@ namespace AppStore
iconBox.SizeMode = PictureBoxSizeMode.StretchImage; iconBox.SizeMode = PictureBoxSizeMode.StretchImage;
this.Controls.Add(iconBox); this.Controls.Add(iconBox);
// 工具名称 // 工具名称 - 使用Panel包裹Label实现边框颜色
namePanel = new Panel();
namePanel.Size = new Size(Width - 20, 30);
namePanel.Location = new Point(10, 100);
namePanel.Paint += (sender, e) => {
ControlPaint.DrawBorder(e.Graphics, namePanel.ClientRectangle,
borderColor, ButtonBorderStyle.Solid);
};
nameLabel = new Label(); nameLabel = new Label();
nameLabel.AutoSize = false; nameLabel.Dock = DockStyle.Fill;
nameLabel.Size = new Size(Width - 20, 30);
nameLabel.Location = new Point(10, 100);
nameLabel.Font = new Font("Microsoft YaHei", 10, FontStyle.Bold); nameLabel.Font = new Font("Microsoft YaHei", 10, FontStyle.Bold);
nameLabel.TextAlign = ContentAlignment.MiddleCenter; nameLabel.TextAlign = ContentAlignment.MiddleCenter;
this.Controls.Add(nameLabel); namePanel.Controls.Add(nameLabel);
// 初始主题设置
UpdateLabelTheme();
// 订阅主题变化事件
ThemeManager.ThemeChanged += (theme) => UpdateLabelTheme();
this.Controls.Add(namePanel);
// 打开按钮 // 打开按钮
var openButton = new Button(); var openButton = new Button();
@@ -68,10 +84,30 @@ namespace AppStore
openButton.FlatAppearance.MouseDownBackColor = Color.FromArgb(0, 80, 160); openButton.FlatAppearance.MouseDownBackColor = Color.FromArgb(0, 80, 160);
} }
private void UpdateLabelTheme()
{
if (ThemeManager.CurrentTheme == ThemeManager.ThemeMode.Dark)
{
nameLabel.BackColor = Color.Black;
nameLabel.ForeColor = Color.White;
namePanel.BackColor = Color.Black;
borderColor = Color.White;
}
else
{
nameLabel.BackColor = Color.White;
nameLabel.ForeColor = Color.Black;
namePanel.BackColor = Color.White;
borderColor = SystemColors.ControlDark;
}
namePanel.Invalidate(); // 触发重绘
}
public void UpdateDisplay() public void UpdateDisplay()
{ {
nameLabel.Text = ToolName; nameLabel.Text = ToolName;
iconBox.Image = ToolIcon; iconBox.Image = ToolIcon;
UpdateLabelTheme();
} }
} }
} }

View File

@@ -2,7 +2,7 @@
; 有关创建 Inno Setup 脚本文件的详细信息,请参阅帮助文档! ; 有关创建 Inno Setup 脚本文件的详细信息,请参阅帮助文档!
#define MyAppName "kortapp-z" #define MyAppName "kortapp-z"
#define MyAppVersion "1.1.0" #define MyAppVersion "1.1.2"
#define MyAppPublisher "zsyg" #define MyAppPublisher "zsyg"
#define MyAppURL "https://github.com/zs-yg/kortapp-z" #define MyAppURL "https://github.com/zs-yg/kortapp-z"
#define MyAppExeName "kortapp.exe" #define MyAppExeName "kortapp.exe"

View File

@@ -2,7 +2,7 @@
; 有关创建 Inno Setup 脚本文件的详细信息,请参阅帮助文档! ; 有关创建 Inno Setup 脚本文件的详细信息,请参阅帮助文档!
#define MyAppName "kortapp-z" #define MyAppName "kortapp-z"
#define MyAppVersion "1.1.0" #define MyAppVersion "1.1.2"
#define MyAppPublisher "zsyg" #define MyAppPublisher "zsyg"
#define MyAppURL "https://github.com/zs-yg/kortapp-z" #define MyAppURL "https://github.com/zs-yg/kortapp-z"
#define MyAppExeName "kortapp.exe" #define MyAppExeName "kortapp.exe"