From f7250dae08648d3ae04e8618acb4842138cf9935 Mon Sep 17 00:00:00 2001 From: zsyg <3872006562@qq.com> Date: Tue, 1 Jul 2025 10:26:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=BB=E9=A2=98=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E5=B8=A6=E6=9D=A5=E7=9A=84=E9=A2=9C=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AppCard.cs | 47 +- MainForm.cs | 2870 ++++++++++++++++++++-------------------- ToolCard.cs | 46 +- inno/innosetup_x64.iss | 2 +- inno/innosetup_x86.iss | 2 +- 5 files changed, 1520 insertions(+), 1447 deletions(-) diff --git a/AppCard.cs b/AppCard.cs index c11485f..eef218f 100644 --- a/AppCard.cs +++ b/AppCard.cs @@ -13,7 +13,9 @@ namespace AppStore { private PictureBox iconBox; private Label nameLabel; + private Panel namePanel; private Button downloadBtn; + private Color borderColor = SystemColors.ControlDark; private static readonly ConcurrentDictionary PathCache = new ConcurrentDictionary(); @@ -27,6 +29,7 @@ namespace AppStore // 确保关键对象不为null iconBox = new PictureBox() { SizeMode = PictureBoxSizeMode.StretchImage }; nameLabel = new Label() { Text = string.Empty }; + namePanel = new Panel(); downloadBtn = new Button() { Text = "下载" }; // 确保DownloadManager已初始化 @@ -57,14 +60,29 @@ namespace AppStore iconBox.SizeMode = PictureBoxSizeMode.StretchImage; 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.AutoSize = false; - nameLabel.Size = new Size(Width - 20, 40); - nameLabel.Location = new Point(10, 100); + nameLabel.Dock = DockStyle.Fill; nameLabel.Font = new Font("Microsoft YaHei", 10, FontStyle.Bold); nameLabel.TextAlign = ContentAlignment.MiddleCenter; - this.Controls.Add(nameLabel); + + namePanel.Controls.Add(nameLabel); + + // 初始主题设置 + UpdateLabelTheme(); + + // 订阅主题变化事件 + ThemeManager.ThemeChanged += (theme) => UpdateLabelTheme(); + + this.Controls.Add(namePanel); // 下载按钮 downloadBtn = new Button(); @@ -92,6 +110,25 @@ namespace AppStore 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(); // 触发重绘 + } + /// /// 初始化卡片边框路径 /// 使用C++程序计算高性能边框路径并缓存结果 diff --git a/MainForm.cs b/MainForm.cs index 400de7b..6057e66 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -1,1435 +1,1435 @@ -#nullable enable -using System; -using System.Drawing; -using System.Windows.Forms; -using System.IO; -using System.Security.Cryptography; -using System.Text; -using System.Text.Json; -using System.Diagnostics; -using AppStore; - -namespace AppStore -{ - /// - /// 主窗体类,负责应用程序的主界面显示和交互 - /// - public class MainForm : Form - { - private static readonly string CacheDir = Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), - "zsyg", "kortapp-z", ".cache"); - - private class AppPositionCache - { - public string AppName { get; set; } = string.Empty; - public int X { get; set; } - public int Y { get; set; } - public DateTime LastUpdated { get; set; } = DateTime.Now; - } - - private static string GetPositionCacheFilePath(string appName) - { - using var md5 = MD5.Create(); - var hash = md5.ComputeHash(Encoding.UTF8.GetBytes(appName)); - var fileName = BitConverter.ToString(hash).Replace("-", "").ToLower() + ".json"; - return Path.Combine(CacheDir, fileName); - } - - private static void EnsureCacheDirectory() - { - try - { - if (!Directory.Exists(CacheDir)) - { - Directory.CreateDirectory(CacheDir); - Logger.Log($"已创建缓存目录: {CacheDir}"); - } - } - catch (Exception ex) - { - Logger.LogError($"创建缓存目录失败: {CacheDir}", ex); - throw; - } - } - - private static bool TryReadPositionCache(string appName, out AppPositionCache? cacheData) - { - cacheData = null; - var cacheFile = GetPositionCacheFilePath(appName); - - if (!File.Exists(cacheFile)) - return false; - - try - { - var json = File.ReadAllText(cacheFile); - cacheData = JsonSerializer.Deserialize(json); - return cacheData != null; - } - catch - { - return false; - } - } - - private static void WritePositionCache(string appName, Point position) - { - try - { - EnsureCacheDirectory(); - var cacheFile = GetPositionCacheFilePath(appName); - - var cacheData = new AppPositionCache - { - AppName = appName, - X = position.X, - Y = position.Y, - LastUpdated = DateTime.Now - }; - - var json = JsonSerializer.Serialize(cacheData); - File.WriteAllText(cacheFile, json); - Logger.Log($"已保存位置缓存: {appName} ({position.X}, {position.Y})"); - } - catch (Exception ex) - { - Logger.LogError($"保存位置缓存失败: {appName}", ex); - throw; - } - } - - private static bool IsPositionCacheValid(AppPositionCache cacheData) - { - // 缓存有效期设为7天 - return (DateTime.Now - cacheData.LastUpdated).TotalDays <= 7; - } - - private static void SaveAllCardPositions(FlowLayoutPanel flowPanel) - { - foreach (Control control in flowPanel.Controls) - { - if (control is AppCard card) - { - WritePositionCache(card.AppName, control.Location); - } - } - } - - // 软件下载按钮 - private Button btnApps = null!; - // 下载进度按钮 - private Button btnDownloads = null!; - // 设置按钮 - private Button btnSettings = null!; - // 关于按钮 - private Button btnAbout = null!; - // 内容显示面板 - private Panel contentPanel = null!; - - /// - /// 初始化窗体组件 - /// - private void InitializeComponent() - { - // 设置窗体基本属性 - // 窗体基本设置 - this.Text = "kortapp-z"; - this.Size = new Size(1430, 1050); // 增加窗体高度 - this.MinimumSize = new Size(600, 600); // 设置最小尺寸 - this.StartPosition = FormStartPosition.CenterScreen; - this.Icon = new Icon("img/ico/icon.ico"); // 设置窗体图标 - - // 注册主题变更事件 - ThemeManager.ThemeChanged += (theme) => - { - this.Invoke((MethodInvoker)delegate { - AnimateThemeChange(); - }); - }; - - // 现代化顶部导航栏 - Panel buttonPanel = new Panel(); - buttonPanel.Dock = DockStyle.Top; - buttonPanel.Height = 70; - buttonPanel.BackColor = ThemeManager.ControlBackgroundColor; - buttonPanel.Padding = new Padding(10, 15, 10, 0); - buttonPanel.AutoScroll = true; - buttonPanel.AutoSize = true; - buttonPanel.AutoSizeMode = AutoSizeMode.GrowAndShrink; - - // 导航按钮样式 - Action