优化默认菜单颜色显示

添加主题切换按钮
优化图片显示计数
This commit is contained in:
尚美 2025-03-12 18:03:58 +08:00
parent beb88e236d
commit 60db9fd0c2

View File

@ -34,17 +34,17 @@ namespace QuickLauncher
private class RoundedPanel : Panel private class RoundedPanel : Panel
{ {
private int _cornerRadius = 8; private int _cornerRadius = 8;
public int CornerRadius public int CornerRadius
{ {
get { return _cornerRadius; } get { return _cornerRadius; }
set { _cornerRadius = value; Invalidate(); } set { _cornerRadius = value; Invalidate(); }
} }
protected override void OnPaint(PaintEventArgs e) protected override void OnPaint(PaintEventArgs e)
{ {
base.OnPaint(e); base.OnPaint(e);
// 创建圆角路径 // 创建圆角路径
using (GraphicsPath path = new GraphicsPath()) using (GraphicsPath path = new GraphicsPath())
{ {
@ -53,27 +53,27 @@ namespace QuickLauncher
path.AddArc(Width - CornerRadius, Height - CornerRadius, CornerRadius, CornerRadius, 0, 90); path.AddArc(Width - CornerRadius, Height - CornerRadius, CornerRadius, CornerRadius, 0, 90);
path.AddArc(0, Height - CornerRadius, CornerRadius, CornerRadius, 90, 90); path.AddArc(0, Height - CornerRadius, CornerRadius, CornerRadius, 90, 90);
path.CloseAllFigures(); path.CloseAllFigures();
this.Region = new Region(path); this.Region = new Region(path);
} }
} }
} }
// 添加圆角按钮支持的类 // 添加圆角按钮支持的类
private class RoundedButton : Button private class RoundedButton : Button
{ {
private int _cornerRadius = 8; private int _cornerRadius = 8;
public int CornerRadius public int CornerRadius
{ {
get { return _cornerRadius; } get { return _cornerRadius; }
set { _cornerRadius = value; Invalidate(); } set { _cornerRadius = value; Invalidate(); }
} }
protected override void OnPaint(PaintEventArgs e) protected override void OnPaint(PaintEventArgs e)
{ {
base.OnPaint(e); base.OnPaint(e);
// 创建圆角路径 // 创建圆角路径
using (GraphicsPath path = new GraphicsPath()) using (GraphicsPath path = new GraphicsPath())
{ {
@ -82,7 +82,7 @@ namespace QuickLauncher
path.AddArc(Width - CornerRadius, Height - CornerRadius, CornerRadius, CornerRadius, 0, 90); path.AddArc(Width - CornerRadius, Height - CornerRadius, CornerRadius, CornerRadius, 0, 90);
path.AddArc(0, Height - CornerRadius, CornerRadius, CornerRadius, 90, 90); path.AddArc(0, Height - CornerRadius, CornerRadius, CornerRadius, 90, 90);
path.CloseAllFigures(); path.CloseAllFigures();
this.Region = new Region(path); this.Region = new Region(path);
} }
} }
@ -101,7 +101,7 @@ namespace QuickLauncher
private const int MIN_ICON_SIZE = 24; // 最小图标大小 private const int MIN_ICON_SIZE = 24; // 最小图标大小
private const int MAX_ICON_SIZE = 256; // 增加最大图标大小到256 private const int MAX_ICON_SIZE = 256; // 增加最大图标大小到256
private const int ICON_SIZE_STEP = 16; // 增加每次缩放的步长 private const int ICON_SIZE_STEP = 16; // 增加每次缩放的步长
// 左侧面板调整相关 // 左侧面板调整相关
private bool isResizing = false; private bool isResizing = false;
private int resizingStartX = 0; private int resizingStartX = 0;
@ -124,7 +124,7 @@ namespace QuickLauncher
public MainForm() public MainForm()
{ {
InitializeComponent(); InitializeComponent();
// 配置工具提示 - 调整为更合适的值 // 配置工具提示 - 调整为更合适的值
toolTip1 = new ToolTip(); toolTip1 = new ToolTip();
toolTip1.AutoPopDelay = 5000; toolTip1.AutoPopDelay = 5000;
@ -133,13 +133,13 @@ namespace QuickLauncher
toolTip1.ShowAlways = true; toolTip1.ShowAlways = true;
toolTip1.UseFading = true; toolTip1.UseFading = true;
toolTip1.IsBalloon = false; // 使用标准样式 toolTip1.IsBalloon = false; // 使用标准样式
// 初始化数据和UI // 初始化数据和UI
InitializeUI(); InitializeUI();
// 应用Windows 11风格 // 应用Windows 11风格
ApplyWin11Style(); ApplyWin11Style();
SetupContextMenus(); SetupContextMenus();
SetupEventHandlers(); SetupEventHandlers();
LoadSettings(); LoadSettings();
@ -170,7 +170,7 @@ namespace QuickLauncher
{ {
// 更新深色模式状态 // 更新深色模式状态
isDarkMode = IsSystemUsingSysemDarkTheme(); isDarkMode = IsSystemUsingSysemDarkTheme();
// 重新应用Windows 11风格 // 重新应用Windows 11风格
ApplyWin11Style(); ApplyWin11Style();
} }
@ -180,7 +180,7 @@ namespace QuickLauncher
{ {
// 检测系统主题 // 检测系统主题
isDarkMode = IsSystemUsingSysemDarkTheme(); isDarkMode = IsSystemUsingSysemDarkTheme();
// 应用Mica效果 // 应用Mica效果
if (Environment.OSVersion.Version.Build >= 22000) // Windows 11 if (Environment.OSVersion.Version.Build >= 22000) // Windows 11
{ {
@ -189,7 +189,7 @@ namespace QuickLauncher
// 应用深色/浅色模式 // 应用深色/浅色模式
int darkMode = isDarkMode ? 1 : 0; int darkMode = isDarkMode ? 1 : 0;
DwmSetWindowAttribute(this.Handle, DWMWA_USE_IMMERSIVE_DARK_MODE, ref darkMode, sizeof(int)); DwmSetWindowAttribute(this.Handle, DWMWA_USE_IMMERSIVE_DARK_MODE, ref darkMode, sizeof(int));
// 应用Mica效果 // 应用Mica效果
int micaEffect = 1; int micaEffect = 1;
DwmSetWindowAttribute(this.Handle, DWMWA_MICA_EFFECT, ref micaEffect, sizeof(int)); DwmSetWindowAttribute(this.Handle, DWMWA_MICA_EFFECT, ref micaEffect, sizeof(int));
@ -205,11 +205,11 @@ namespace QuickLauncher
// 在Windows 10上使用备用方案 // 在Windows 10上使用备用方案
this.BackColor = isDarkMode ? darkBackColor : lightBackColor; this.BackColor = isDarkMode ? darkBackColor : lightBackColor;
} }
// 应用主题颜色 // 应用主题颜色
ApplyThemeColors(); ApplyThemeColors();
} }
// 检测系统是否使用深色主题 // 检测系统是否使用深色主题
private bool IsSystemUsingSysemDarkTheme() private bool IsSystemUsingSysemDarkTheme()
{ {
@ -228,42 +228,45 @@ namespace QuickLauncher
} }
} }
catch { } catch { }
return false; return false;
} }
// 应用主题颜色 // 应用主题颜色
private void ApplyThemeColors() private void ApplyThemeColors()
{ {
// 设置主窗体颜色 // 设置主窗体颜色
this.ForeColor = isDarkMode ? darkTextColor : lightTextColor; this.ForeColor = isDarkMode ? darkTextColor : lightTextColor;
// 设置左侧面板颜色 // 设置左侧面板颜色
leftPanel.BackColor = isDarkMode ? Color.FromArgb(40, 40, 40) : Color.FromArgb(243, 243, 243); leftPanel.BackColor = isDarkMode ? Color.FromArgb(40, 40, 40) : Color.FromArgb(243, 243, 243);
// 设置右侧面板颜色 // 设置右侧面板颜色
rightPanel.BackColor = isDarkMode ? Color.FromArgb(32, 32, 32) : Color.FromArgb(250, 250, 250); rightPanel.BackColor = isDarkMode ? Color.FromArgb(32, 32, 32) : Color.FromArgb(250, 250, 250);
// 设置工具面板颜色 // 设置工具面板颜色
toolPanel.BackColor = isDarkMode ? Color.FromArgb(45, 45, 45) : Color.FromArgb(230, 230, 230); toolPanel.BackColor = isDarkMode ? Color.FromArgb(45, 45, 45) : Color.FromArgb(230, 230, 230);
// 设置快捷方式面板颜色 // 设置快捷方式面板颜色
shortcutsPanel.BackColor = isDarkMode ? Color.FromArgb(32, 32, 32) : Color.FromArgb(250, 250, 250); shortcutsPanel.BackColor = isDarkMode ? Color.FromArgb(32, 32, 32) : Color.FromArgb(250, 250, 250);
// 设置分类文字颜色
categoryLabel.ForeColor = isDarkMode ? Color.FromArgb(255, 255, 255) : Color.FromArgb(0, 0, 0);
// 设置添加按钮颜色 // 设置添加按钮颜色
addButton.BackColor = accentColor; addButton.BackColor = accentColor;
addButton.ForeColor = Color.White; addButton.ForeColor = Color.White;
addButton.FlatAppearance.BorderSize = 0; addButton.FlatAppearance.BorderSize = 0;
// 设置菜单颜色 // 设置菜单颜色
menuStrip.BackColor = isDarkMode ? Color.FromArgb(45, 45, 45) : Color.FromArgb(230, 230, 230); menuStrip.BackColor = isDarkMode ? Color.FromArgb(45, 45, 45) : Color.FromArgb(230, 230, 230);
menuStrip.ForeColor = isDarkMode ? darkTextColor : lightTextColor; menuStrip.ForeColor = isDarkMode ? darkTextColor : lightTextColor;
// 设置菜单项颜色 // 设置菜单项颜色
foreach (ToolStripMenuItem item in menuStrip.Items) foreach (ToolStripMenuItem item in menuStrip.Items)
{ {
item.ForeColor = isDarkMode ? Color.White : Color.Black; item.ForeColor = isDarkMode ? Color.White : Color.Black;
// 设置下拉菜单项颜色 // 设置下拉菜单项颜色
foreach (ToolStripItem dropItem in item.DropDownItems) foreach (ToolStripItem dropItem in item.DropDownItems)
{ {
@ -273,10 +276,10 @@ namespace QuickLauncher
} }
} }
} }
// 设置菜单渲染器 // 设置菜单渲染器
menuStrip.Renderer = new ModernMenuRenderer(isDarkMode); menuStrip.Renderer = new ModernMenuRenderer(isDarkMode);
// 刷新分类列表和当前分类的快捷方式仅当categories已初始化时 // 刷新分类列表和当前分类的快捷方式仅当categories已初始化时
if (categories != null) if (categories != null)
{ {
@ -296,7 +299,7 @@ namespace QuickLauncher
categoryContextMenu.Items.Add("添加新分类", null, (s, e) => AddCategory_Click(s, e)); categoryContextMenu.Items.Add("添加新分类", null, (s, e) => AddCategory_Click(s, e));
categoryContextMenu.Items.Add("删除当前分类", null, (s, e) => DeleteCategory_Click(s, e)); categoryContextMenu.Items.Add("删除当前分类", null, (s, e) => DeleteCategory_Click(s, e));
categoryContextMenu.Items.Add("重命名分类", null, (s, e) => RenameCategory_Click(s, e)); categoryContextMenu.Items.Add("重命名分类", null, (s, e) => RenameCategory_Click(s, e));
// 应用主题颜色 // 应用主题颜色
categoryContextMenu.Renderer = new ModernMenuRenderer(isDarkMode); categoryContextMenu.Renderer = new ModernMenuRenderer(isDarkMode);
@ -308,7 +311,7 @@ namespace QuickLauncher
shortcutsPanelContextMenu.Items.Add("按添加时间排序", null, (s, e) => SortShortcuts("DateAdded")); shortcutsPanelContextMenu.Items.Add("按添加时间排序", null, (s, e) => SortShortcuts("DateAdded"));
shortcutsPanelContextMenu.Items.Add("按使用频率排序", null, (s, e) => SortShortcuts("UsageCount")); shortcutsPanelContextMenu.Items.Add("按使用频率排序", null, (s, e) => SortShortcuts("UsageCount"));
shortcutsPanelContextMenu.Items.Add("-"); // 分隔线 shortcutsPanelContextMenu.Items.Add("-"); // 分隔线
// 添加图标大小调整菜单,增加更多选项 // 添加图标大小调整菜单,增加更多选项
var sizeMenu = new ToolStripMenuItem("图标大小"); var sizeMenu = new ToolStripMenuItem("图标大小");
sizeMenu.DropDownItems.Add("超小图标 (24px)", null, (s, e) => { ResizeIcons(24); }); sizeMenu.DropDownItems.Add("超小图标 (24px)", null, (s, e) => { ResizeIcons(24); });
@ -319,7 +322,7 @@ namespace QuickLauncher
sizeMenu.DropDownItems.Add("超大图标 (192px)", null, (s, e) => { ResizeIcons(192); }); sizeMenu.DropDownItems.Add("超大图标 (192px)", null, (s, e) => { ResizeIcons(192); });
sizeMenu.DropDownItems.Add("巨大图标 (256px)", null, (s, e) => { ResizeIcons(256); }); sizeMenu.DropDownItems.Add("巨大图标 (256px)", null, (s, e) => { ResizeIcons(256); });
shortcutsPanelContextMenu.Items.Add(sizeMenu); shortcutsPanelContextMenu.Items.Add(sizeMenu);
// 添加主题切换选项 // 添加主题切换选项
shortcutsPanelContextMenu.Items.Add("-"); // 分隔线 shortcutsPanelContextMenu.Items.Add("-"); // 分隔线
var themeMenu = new ToolStripMenuItem("主题设置"); var themeMenu = new ToolStripMenuItem("主题设置");
@ -327,79 +330,79 @@ namespace QuickLauncher
themeMenu.DropDownItems.Add("深色主题", null, (s, e) => { ChangeTheme(true); }); themeMenu.DropDownItems.Add("深色主题", null, (s, e) => { ChangeTheme(true); });
themeMenu.DropDownItems.Add("跟随系统", null, (s, e) => { FollowSystemTheme(); }); themeMenu.DropDownItems.Add("跟随系统", null, (s, e) => { FollowSystemTheme(); });
shortcutsPanelContextMenu.Items.Add(themeMenu); shortcutsPanelContextMenu.Items.Add(themeMenu);
// 应用主题颜色 // 应用主题颜色
shortcutsPanelContextMenu.Renderer = new ModernMenuRenderer(isDarkMode); shortcutsPanelContextMenu.Renderer = new ModernMenuRenderer(isDarkMode);
// 快捷方式项目右键菜单 // 快捷方式项目右键菜单
shortcutItemContextMenu = new ContextMenuStrip(); shortcutItemContextMenu = new ContextMenuStrip();
shortcutItemContextMenu.Items.Add("启动", null, (s, e) => shortcutItemContextMenu.Items.Add("启动", null, (s, e) =>
{ {
if (s is ToolStripMenuItem menuItem && menuItem.Tag is ShortcutItem item) if (s is ToolStripMenuItem menuItem && menuItem.Tag is ShortcutItem item)
{ {
LaunchApplication(item.Path); LaunchApplication(item.Path);
} }
}); });
shortcutItemContextMenu.Items.Add("删除", null, (s, e) => shortcutItemContextMenu.Items.Add("删除", null, (s, e) =>
{ {
if (s is ToolStripMenuItem menuItem && menuItem.Tag is ShortcutItem item) if (s is ToolStripMenuItem menuItem && menuItem.Tag is ShortcutItem item)
{ {
DeleteShortcut(item); DeleteShortcut(item);
} }
}); });
shortcutItemContextMenu.Items.Add("重命名", null, (s, e) => shortcutItemContextMenu.Items.Add("重命名", null, (s, e) =>
{ {
if (s is ToolStripMenuItem menuItem && menuItem.Tag is ShortcutItem item) if (s is ToolStripMenuItem menuItem && menuItem.Tag is ShortcutItem item)
{ {
RenameShortcut(item); RenameShortcut(item);
} }
}); });
shortcutItemContextMenu.Items.Add("属性", null, (s, e) => shortcutItemContextMenu.Items.Add("属性", null, (s, e) =>
{ {
if (s is ToolStripMenuItem menuItem && menuItem.Tag is ShortcutItem item) if (s is ToolStripMenuItem menuItem && menuItem.Tag is ShortcutItem item)
{ {
ShowShortcutProperties(item); ShowShortcutProperties(item);
} }
}); });
// 应用主题颜色 // 应用主题颜色
shortcutItemContextMenu.Renderer = new ModernMenuRenderer(isDarkMode); shortcutItemContextMenu.Renderer = new ModernMenuRenderer(isDarkMode);
} }
// 切换主题 // 切换主题
private void ChangeTheme(bool darkMode) private void ChangeTheme(bool darkMode)
{ {
isDarkMode = darkMode; isDarkMode = darkMode;
ApplyThemeColors(); ApplyThemeColors();
// 更新上下文菜单渲染器 // 更新上下文菜单渲染器
categoryContextMenu.Renderer = new ModernMenuRenderer(isDarkMode); categoryContextMenu.Renderer = new ModernMenuRenderer(isDarkMode);
shortcutsPanelContextMenu.Renderer = new ModernMenuRenderer(isDarkMode); shortcutsPanelContextMenu.Renderer = new ModernMenuRenderer(isDarkMode);
shortcutItemContextMenu.Renderer = new ModernMenuRenderer(isDarkMode); shortcutItemContextMenu.Renderer = new ModernMenuRenderer(isDarkMode);
} }
// 跟随系统主题 // 跟随系统主题
private void FollowSystemTheme() private void FollowSystemTheme()
{ {
isDarkMode = IsSystemUsingSysemDarkTheme(); isDarkMode = IsSystemUsingSysemDarkTheme();
ApplyThemeColors(); ApplyThemeColors();
// 更新上下文菜单渲染器 // 更新上下文菜单渲染器
categoryContextMenu.Renderer = new ModernMenuRenderer(isDarkMode); categoryContextMenu.Renderer = new ModernMenuRenderer(isDarkMode);
shortcutsPanelContextMenu.Renderer = new ModernMenuRenderer(isDarkMode); shortcutsPanelContextMenu.Renderer = new ModernMenuRenderer(isDarkMode);
shortcutItemContextMenu.Renderer = new ModernMenuRenderer(isDarkMode); shortcutItemContextMenu.Renderer = new ModernMenuRenderer(isDarkMode);
} }
// 现代菜单渲染器 // 现代菜单渲染器
private class ModernMenuRenderer : ToolStripProfessionalRenderer private class ModernMenuRenderer : ToolStripProfessionalRenderer
{ {
private bool _isDarkMode; private bool _isDarkMode;
public ModernMenuRenderer(bool isDarkMode) : base(new ModernColorTable(isDarkMode)) public ModernMenuRenderer(bool isDarkMode) : base(new ModernColorTable(isDarkMode))
{ {
_isDarkMode = isDarkMode; _isDarkMode = isDarkMode;
} }
protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e) protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e)
{ {
if (e.Item.Selected) if (e.Item.Selected)
@ -422,7 +425,7 @@ namespace QuickLauncher
} }
} }
} }
protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e) protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
{ {
// 菜单背景 // 菜单背景
@ -432,14 +435,14 @@ namespace QuickLauncher
e.Graphics.FillRectangle(brush, e.AffectedBounds); e.Graphics.FillRectangle(brush, e.AffectedBounds);
} }
} }
protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e) protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e)
{ {
// 菜单文本颜色 // 菜单文本颜色
e.TextColor = _isDarkMode ? Color.FromArgb(240, 240, 240) : Color.FromArgb(20, 20, 20); e.TextColor = _isDarkMode ? Color.FromArgb(240, 240, 240) : Color.FromArgb(20, 20, 20);
base.OnRenderItemText(e); base.OnRenderItemText(e);
} }
protected override void OnRenderSeparator(ToolStripSeparatorRenderEventArgs e) protected override void OnRenderSeparator(ToolStripSeparatorRenderEventArgs e)
{ {
// 分隔线颜色 // 分隔线颜色
@ -451,28 +454,28 @@ namespace QuickLauncher
} }
} }
} }
// 现代菜单颜色表 // 现代菜单颜色表
private class ModernColorTable : ProfessionalColorTable private class ModernColorTable : ProfessionalColorTable
{ {
private bool _isDarkMode; private bool _isDarkMode;
public ModernColorTable(bool isDarkMode) public ModernColorTable(bool isDarkMode)
{ {
_isDarkMode = isDarkMode; _isDarkMode = isDarkMode;
} }
// 菜单项 // 菜单项
public override Color MenuItemSelected => _isDarkMode ? Color.FromArgb(70, 70, 70) : Color.FromArgb(210, 230, 250); public override Color MenuItemSelected => _isDarkMode ? Color.FromArgb(70, 70, 70) : Color.FromArgb(210, 230, 250);
public override Color MenuItemBorder => Color.Transparent; public override Color MenuItemBorder => Color.Transparent;
// 菜单栏 // 菜单栏
public override Color MenuBorder => Color.Transparent; public override Color MenuBorder => Color.Transparent;
public override Color MenuItemSelectedGradientBegin => _isDarkMode ? Color.FromArgb(70, 70, 70) : Color.FromArgb(210, 230, 250); public override Color MenuItemSelectedGradientBegin => _isDarkMode ? Color.FromArgb(70, 70, 70) : Color.FromArgb(210, 230, 250);
public override Color MenuItemSelectedGradientEnd => _isDarkMode ? Color.FromArgb(70, 70, 70) : Color.FromArgb(210, 230, 250); public override Color MenuItemSelectedGradientEnd => _isDarkMode ? Color.FromArgb(70, 70, 70) : Color.FromArgb(210, 230, 250);
public override Color MenuItemPressedGradientBegin => _isDarkMode ? Color.FromArgb(80, 80, 80) : Color.FromArgb(190, 210, 240); public override Color MenuItemPressedGradientBegin => _isDarkMode ? Color.FromArgb(80, 80, 80) : Color.FromArgb(190, 210, 240);
public override Color MenuItemPressedGradientEnd => _isDarkMode ? Color.FromArgb(80, 80, 80) : Color.FromArgb(190, 210, 240); public override Color MenuItemPressedGradientEnd => _isDarkMode ? Color.FromArgb(80, 80, 80) : Color.FromArgb(190, 210, 240);
// 工具栏 // 工具栏
public override Color ToolStripDropDownBackground => _isDarkMode ? Color.FromArgb(45, 45, 45) : Color.FromArgb(250, 250, 250); public override Color ToolStripDropDownBackground => _isDarkMode ? Color.FromArgb(45, 45, 45) : Color.FromArgb(250, 250, 250);
public override Color ImageMarginGradientBegin => _isDarkMode ? Color.FromArgb(45, 45, 45) : Color.FromArgb(250, 250, 250); public override Color ImageMarginGradientBegin => _isDarkMode ? Color.FromArgb(45, 45, 45) : Color.FromArgb(250, 250, 250);
@ -488,7 +491,7 @@ namespace QuickLauncher
iconSize = newSize; iconSize = newSize;
settings.IconSize = iconSize; settings.IconSize = iconSize;
SaveSettings(); SaveSettings();
if (!string.IsNullOrEmpty(currentCategory)) if (!string.IsNullOrEmpty(currentCategory))
{ {
ShowCategoryItems(currentCategory); ShowCategoryItems(currentCategory);
@ -548,10 +551,10 @@ namespace QuickLauncher
var items = categories[currentCategory]; var items = categories[currentCategory];
categories.Remove(currentCategory); categories.Remove(currentCategory);
categories[newName] = items; categories[newName] = items;
string oldCategory = currentCategory; string oldCategory = currentCategory;
currentCategory = newName; currentCategory = newName;
SaveData(); SaveData();
RefreshCategoryList(); RefreshCategoryList();
ShowCategoryItems(currentCategory); ShowCategoryItems(currentCategory);
@ -668,7 +671,7 @@ namespace QuickLauncher
var button = new RoundedButton() { Text = "确定", DialogResult = DialogResult.OK, Location = new Point(150, 220), CornerRadius = cornerRadius, BackColor = accentColor, ForeColor = Color.White }; var button = new RoundedButton() { Text = "确定", DialogResult = DialogResult.OK, Location = new Point(150, 220), CornerRadius = cornerRadius, BackColor = accentColor, ForeColor = Color.White };
dialog.Controls.AddRange(new Control[] { icon, nameLabel, nameValue, pathLabel, pathValue, dialog.Controls.AddRange(new Control[] { icon, nameLabel, nameValue, pathLabel, pathValue,
dateLabel, dateValue, usageLabel, usageValue, button }); dateLabel, dateValue, usageLabel, usageValue, button });
dialog.AcceptButton = button; dialog.AcceptButton = button;
@ -684,7 +687,7 @@ namespace QuickLauncher
return; return;
// 尝试选择上次选择的分类 // 尝试选择上次选择的分类
if (!string.IsNullOrEmpty(settings.LastSelectedCategory) && if (!string.IsNullOrEmpty(settings.LastSelectedCategory) &&
categories.ContainsKey(settings.LastSelectedCategory)) categories.ContainsKey(settings.LastSelectedCategory))
{ {
currentCategory = settings.LastSelectedCategory; currentCategory = settings.LastSelectedCategory;
@ -748,10 +751,10 @@ namespace QuickLauncher
shortcutsPanel.AllowDrop = true; shortcutsPanel.AllowDrop = true;
shortcutsPanel.DragEnter += ShortcutsPanel_DragEnter; shortcutsPanel.DragEnter += ShortcutsPanel_DragEnter;
shortcutsPanel.DragDrop += ShortcutsPanel_DragDrop; shortcutsPanel.DragDrop += ShortcutsPanel_DragDrop;
// 添加鼠标滚轮事件处理 // 添加鼠标滚轮事件处理
shortcutsPanel.MouseWheel += ShortcutsPanel_MouseWheel; shortcutsPanel.MouseWheel += ShortcutsPanel_MouseWheel;
// 为shortcutsPanel添加鼠标移动事件用于处理空白区域的工具提示 // 为shortcutsPanel添加鼠标移动事件用于处理空白区域的工具提示
shortcutsPanel.MouseMove += ShortcutsPanel_MouseMove; shortcutsPanel.MouseMove += ShortcutsPanel_MouseMove;
@ -778,7 +781,7 @@ namespace QuickLauncher
e.Effect = DragDropEffects.None; e.Effect = DragDropEffects.None;
} }
} }
private void ShortcutsPanel_DragDrop(object sender, DragEventArgs e) private void ShortcutsPanel_DragDrop(object sender, DragEventArgs e)
{ {
Console.WriteLine("DragDrop triggered"); Console.WriteLine("DragDrop triggered");
@ -817,29 +820,29 @@ namespace QuickLauncher
{ {
// 初始化数据 // 初始化数据
categories = new Dictionary<string, List<ShortcutItem>>(); categories = new Dictionary<string, List<ShortcutItem>>();
// 设置窗体样式 // 设置窗体样式
this.FormBorderStyle = FormBorderStyle.Sizable; this.FormBorderStyle = FormBorderStyle.Sizable;
this.MinimumSize = new Size(800, 600); this.MinimumSize = new Size(800, 600);
// 设置控件样式 // 设置控件样式
addButton.FlatStyle = FlatStyle.Flat; addButton.FlatStyle = FlatStyle.Flat;
addButton.FlatAppearance.BorderSize = 0; addButton.FlatAppearance.BorderSize = 0;
addButton.BackColor = accentColor; addButton.BackColor = accentColor;
addButton.ForeColor = Color.White; addButton.ForeColor = Color.White;
addButton.Font = new Font("Microsoft YaHei UI", 10, FontStyle.Regular); addButton.Font = new Font("Microsoft YaHei UI", 10, FontStyle.Regular);
// 设置分类标签样式 // 设置分类标签样式
categoryLabel.Font = new Font("Microsoft YaHei UI", 11); categoryLabel.Font = new Font("Microsoft YaHei UI", 11);
categoryLabel.ForeColor = isDarkMode ? Color.Black : Color.White; categoryLabel.ForeColor = isDarkMode ? Color.FromArgb(0, 0, 0) : Color.FromArgb(255, 255, 255);
// 创建左侧面板调整手柄 // 创建左侧面板调整手柄
CreateResizeHandle(); CreateResizeHandle();
// 刷新分类列表 // 刷新分类列表
RefreshCategoryList(); RefreshCategoryList();
} }
// 创建左侧面板调整手柄 // 创建左侧面板调整手柄
private void CreateResizeHandle() private void CreateResizeHandle()
{ {
@ -851,17 +854,17 @@ namespace QuickLauncher
Cursor = Cursors.SizeWE, Cursor = Cursors.SizeWE,
BackColor = Color.Transparent BackColor = Color.Transparent
}; };
// 添加鼠标事件 // 添加鼠标事件
resizeHandle.MouseDown += ResizeHandle_MouseDown; resizeHandle.MouseDown += ResizeHandle_MouseDown;
resizeHandle.MouseMove += ResizeHandle_MouseMove; resizeHandle.MouseMove += ResizeHandle_MouseMove;
resizeHandle.MouseUp += ResizeHandle_MouseUp; resizeHandle.MouseUp += ResizeHandle_MouseUp;
// 添加到左侧面板 // 添加到左侧面板
leftPanel.Controls.Add(resizeHandle); leftPanel.Controls.Add(resizeHandle);
resizeHandle.BringToFront(); resizeHandle.BringToFront();
} }
// 调整手柄鼠标按下事件 // 调整手柄鼠标按下事件
private void ResizeHandle_MouseDown(object sender, MouseEventArgs e) private void ResizeHandle_MouseDown(object sender, MouseEventArgs e)
{ {
@ -870,12 +873,12 @@ namespace QuickLauncher
isResizing = true; isResizing = true;
resizingStartX = e.X; resizingStartX = e.X;
initialPanelWidth = leftPanel.Width; initialPanelWidth = leftPanel.Width;
// 捕获鼠标 // 捕获鼠标
resizeHandle.Capture = true; resizeHandle.Capture = true;
} }
} }
// 调整手柄鼠标移动事件 // 调整手柄鼠标移动事件
private void ResizeHandle_MouseMove(object sender, MouseEventArgs e) private void ResizeHandle_MouseMove(object sender, MouseEventArgs e)
{ {
@ -883,34 +886,34 @@ namespace QuickLauncher
{ {
// 计算新宽度 // 计算新宽度
int newWidth = initialPanelWidth + (e.X - resizingStartX); int newWidth = initialPanelWidth + (e.X - resizingStartX);
// 限制宽度范围 // 限制宽度范围
if (newWidth < MIN_PANEL_WIDTH) if (newWidth < MIN_PANEL_WIDTH)
newWidth = MIN_PANEL_WIDTH; newWidth = MIN_PANEL_WIDTH;
else if (newWidth > MAX_PANEL_WIDTH) else if (newWidth > MAX_PANEL_WIDTH)
newWidth = MAX_PANEL_WIDTH; newWidth = MAX_PANEL_WIDTH;
// 设置新宽度 // 设置新宽度
leftPanel.Width = newWidth; leftPanel.Width = newWidth;
// 刷新布局 // 刷新布局
this.PerformLayout(); this.PerformLayout();
// 刷新分类列表,以适应新宽度 // 刷新分类列表,以适应新宽度
RefreshCategoryList(); RefreshCategoryList();
} }
} }
// 调整手柄鼠标释放事件 // 调整手柄鼠标释放事件
private void ResizeHandle_MouseUp(object sender, MouseEventArgs e) private void ResizeHandle_MouseUp(object sender, MouseEventArgs e)
{ {
if (isResizing) if (isResizing)
{ {
isResizing = false; isResizing = false;
// 释放鼠标捕获 // 释放鼠标捕获
resizeHandle.Capture = false; resizeHandle.Capture = false;
// 保存设置 // 保存设置
settings.LeftPanelWidth = leftPanel.Width; settings.LeftPanelWidth = leftPanel.Width;
SaveSettings(); SaveSettings();
@ -922,30 +925,42 @@ namespace QuickLauncher
using (var dialog = new Form()) using (var dialog = new Form())
{ {
dialog.Text = "添加新分类"; dialog.Text = "添加新分类";
dialog.Size = new Size(350, 150); dialog.Size = new Size(350, 200);
dialog.StartPosition = FormStartPosition.CenterParent; dialog.StartPosition = FormStartPosition.CenterParent;
dialog.FormBorderStyle = FormBorderStyle.FixedDialog; dialog.FormBorderStyle = FormBorderStyle.FixedDialog;
dialog.MaximizeBox = false; dialog.MaximizeBox = false;
dialog.MinimizeBox = false; dialog.MinimizeBox = false;
dialog.BackColor = isDarkMode ? Color.FromArgb(32, 32, 32) : Color.FromArgb(243, 243, 243); dialog.BackColor = isDarkMode ? Color.FromArgb(45, 45, 45) : Color.FromArgb(240, 240, 240);
dialog.ForeColor = isDarkMode ? Color.White : Color.Black; dialog.ForeColor = isDarkMode ? Color.White : Color.Black;
var label = new Label() { // 应用Windows 11深色/浅色模式到标题栏
Text = "分类名称:", if (Environment.OSVersion.Version.Build >= 22000)
{
int darkMode = isDarkMode ? 1 : 0;
DwmSetWindowAttribute(dialog.Handle, DWMWA_USE_IMMERSIVE_DARK_MODE, ref darkMode, sizeof(int));
}
var label = new Label()
{
Text = "分类名称:",
Location = new Point(10, 20), Location = new Point(10, 20),
ForeColor = isDarkMode ? Color.White : Color.Black ForeColor = isDarkMode ? Color.White : Color.Black,
AutoSize = true
}; };
var textBox = new TextBox() { var textBox = new TextBox()
Location = new Point(120, 17), {
Location = new Point(120, 17),
Width = 180, Width = 180,
BackColor = isDarkMode ? Color.FromArgb(45, 45, 45) : Color.White, BackColor = isDarkMode ? Color.FromArgb(60, 60, 60) : Color.White,
ForeColor = isDarkMode ? Color.White : Color.Black ForeColor = isDarkMode ? Color.White : Color.Black,
BorderStyle = BorderStyle.FixedSingle
}; };
var button = new RoundedButton() { var button = new RoundedButton()
Text = "确定", {
DialogResult = DialogResult.OK, Text = "确定",
DialogResult = DialogResult.OK,
Location = new Point(110, 60), Location = new Point(110, 60),
Width = 100, Width = 100,
Height = 30, Height = 30,
@ -957,6 +972,16 @@ namespace QuickLauncher
dialog.Controls.AddRange(new Control[] { label, textBox, button }); dialog.Controls.AddRange(new Control[] { label, textBox, button });
dialog.AcceptButton = button; dialog.AcceptButton = button;
// 确保在显示对话框之前应用主题
dialog.HandleCreated += (s, ev) =>
{
if (Environment.OSVersion.Version.Build >= 22000)
{
int darkMode = isDarkMode ? 1 : 0;
DwmSetWindowAttribute(dialog.Handle, DWMWA_USE_IMMERSIVE_DARK_MODE, ref darkMode, sizeof(int));
}
};
if (dialog.ShowDialog() == DialogResult.OK && !string.IsNullOrWhiteSpace(textBox.Text)) if (dialog.ShowDialog() == DialogResult.OK && !string.IsNullOrWhiteSpace(textBox.Text))
{ {
string newCategory = textBox.Text.Trim(); string newCategory = textBox.Text.Trim();
@ -965,10 +990,9 @@ namespace QuickLauncher
categories[newCategory] = new List<ShortcutItem>(); categories[newCategory] = new List<ShortcutItem>();
SaveData(); SaveData();
RefreshCategoryList(); RefreshCategoryList();
// 自动选择新创建的分类 // 自动选择新创建的分类
currentCategory = newCategory; SwitchCategory(newCategory);
ShowCategoryItems(currentCategory);
} }
} }
} }
@ -990,7 +1014,7 @@ namespace QuickLauncher
RefreshCategoryList(); RefreshCategoryList();
shortcutsPanel.Controls.Clear(); shortcutsPanel.Controls.Clear();
currentCategory = ""; currentCategory = "";
// 删除分类后,选择新的默认分类 // 删除分类后,选择新的默认分类
if (categories.Count > 0) if (categories.Count > 0)
{ {
@ -1005,7 +1029,7 @@ namespace QuickLauncher
// 如果categories为空直接返回 // 如果categories为空直接返回
if (categories == null) if (categories == null)
return; return;
leftPanel.Controls.Clear(); leftPanel.Controls.Clear();
int buttonY = 10; int buttonY = 10;
@ -1026,11 +1050,11 @@ namespace QuickLauncher
Height = CATEGORY_BUTTON_HEIGHT, Height = CATEGORY_BUTTON_HEIGHT,
Location = new Point(10, 0), Location = new Point(10, 0),
FlatStyle = FlatStyle.Flat, FlatStyle = FlatStyle.Flat,
BackColor = category == currentCategory ? BackColor = category == currentCategory ?
accentColor : accentColor :
(isDarkMode ? Color.FromArgb(60, 60, 60) : Color.FromArgb(230, 230, 230)), (isDarkMode ? Color.FromArgb(60, 60, 60) : Color.FromArgb(230, 230, 230)),
ForeColor = category == currentCategory ? ForeColor = category == currentCategory ?
Color.White : Color.White :
(isDarkMode ? Color.FromArgb(240, 240, 240) : Color.FromArgb(20, 20, 20)), (isDarkMode ? Color.FromArgb(240, 240, 240) : Color.FromArgb(20, 20, 20)),
Tag = category, Tag = category,
CornerRadius = cornerRadius, CornerRadius = cornerRadius,
@ -1039,9 +1063,26 @@ namespace QuickLauncher
// 移除旧的事件处理器 // 移除旧的事件处理器
btn.Click -= null; btn.Click -= null;
btn.Click += (s, e) => btn.Click += (s, e) =>
{ {
currentCategory = category; currentCategory = category;
foreach (Control panel in leftPanel.Controls)
{
if (panel is RoundedPanel && panel.Controls.Count > 0)
{
var button = panel.Controls[0] as RoundedButton;
if (button != null)
{
string btnCategory = button.Tag as string;
button.BackColor = btnCategory == category ?
accentColor :
(isDarkMode ? Color.FromArgb(60, 60, 60) : Color.FromArgb(230, 230, 230));
button.ForeColor = btnCategory == category ?
Color.White :
(isDarkMode ? Color.FromArgb(240, 240, 240) : Color.FromArgb(20, 20, 20));
}
}
}
ShowCategoryItems(category); ShowCategoryItems(category);
}; };
@ -1150,7 +1191,7 @@ namespace QuickLauncher
panel.Controls.Add(icon); panel.Controls.Add(icon);
panel.Controls.Add(label); panel.Controls.Add(label);
// 设置右键菜单 // 设置右键菜单
panel.ContextMenuStrip = shortcutItemContextMenu; panel.ContextMenuStrip = shortcutItemContextMenu;
icon.ContextMenuStrip = shortcutItemContextMenu; icon.ContextMenuStrip = shortcutItemContextMenu;
@ -1164,9 +1205,9 @@ namespace QuickLauncher
menuItem.Tag = item; menuItem.Tag = item;
} }
} }
// 双击事件 - 启动应用程序或预览图片 // 双击事件 - 启动应用程序或预览图片
EventHandler doubleClickHandler = (s, e) => EventHandler doubleClickHandler = (s, e) =>
{ {
if (IsImageFile(item.Path)) if (IsImageFile(item.Path))
{ {
@ -1174,14 +1215,14 @@ namespace QuickLauncher
} }
else else
{ {
LaunchApplication(item.Path); LaunchApplication(item.Path); // 启动应用程序
} }
}; };
panel.DoubleClick += doubleClickHandler; panel.DoubleClick += doubleClickHandler;
icon.DoubleClick += doubleClickHandler; icon.DoubleClick += doubleClickHandler;
label.DoubleClick += doubleClickHandler; label.DoubleClick += doubleClickHandler;
// 添加鼠标悬停效果 // 添加鼠标悬停效果
panel.MouseEnter += Panel_MouseEnter; panel.MouseEnter += Panel_MouseEnter;
panel.MouseLeave += Panel_MouseLeave; panel.MouseLeave += Panel_MouseLeave;
@ -1189,7 +1230,7 @@ namespace QuickLauncher
icon.MouseLeave += Panel_MouseLeave; icon.MouseLeave += Panel_MouseLeave;
label.MouseEnter += Panel_MouseEnter; label.MouseEnter += Panel_MouseEnter;
label.MouseLeave += Panel_MouseLeave; label.MouseLeave += Panel_MouseLeave;
// 添加鼠标点击效果 // 添加鼠标点击效果
panel.MouseDown += Panel_MouseDown; panel.MouseDown += Panel_MouseDown;
panel.MouseUp += Panel_MouseUp; panel.MouseUp += Panel_MouseUp;
@ -1197,13 +1238,13 @@ namespace QuickLauncher
icon.MouseUp += Panel_MouseUp; icon.MouseUp += Panel_MouseUp;
label.MouseDown += Panel_MouseDown; label.MouseDown += Panel_MouseDown;
label.MouseUp += Panel_MouseUp; label.MouseUp += Panel_MouseUp;
// 设置工具提示 // 设置工具提示
string tipText = GetTooltipText(item); string tipText = GetTooltipText(item);
toolTip1.SetToolTip(panel, tipText); toolTip1.SetToolTip(panel, tipText);
toolTip1.SetToolTip(icon, tipText); toolTip1.SetToolTip(icon, tipText);
toolTip1.SetToolTip(label, tipText); toolTip1.SetToolTip(label, tipText);
shortcutsPanel.Controls.Add(panel); shortcutsPanel.Controls.Add(panel);
} }
@ -1267,7 +1308,7 @@ namespace QuickLauncher
// 添加ESC键关闭功能 // 添加ESC键关闭功能
previewForm.KeyPreview = true; previewForm.KeyPreview = true;
previewForm.KeyDown += (s, e) => previewForm.KeyDown += (s, e) =>
{ {
if (e.KeyCode == Keys.Escape) if (e.KeyCode == Keys.Escape)
previewForm.Close(); previewForm.Close();
@ -1286,6 +1327,14 @@ namespace QuickLauncher
} }
}; };
var item = categories[currentCategory].FirstOrDefault(i => i.Path == imagePath);
if (item != null)
{
item.UsageCount++;
item.LastUsed = DateTime.Now;
SaveData();
}
previewForm.Controls.Add(pictureBox); previewForm.Controls.Add(pictureBox);
previewForm.ShowDialog(); previewForm.ShowDialog();
} }
@ -1303,7 +1352,7 @@ namespace QuickLauncher
{ {
// 应用悬停效果 // 应用悬停效果
panel.BackColor = isDarkMode ? Color.FromArgb(70, 70, 70) : Color.FromArgb(230, 230, 230); panel.BackColor = isDarkMode ? Color.FromArgb(70, 70, 70) : Color.FromArgb(230, 230, 230);
// 显示工具提示 // 显示工具提示
if (panel.Tag is ShortcutItem item) if (panel.Tag is ShortcutItem item)
{ {
@ -1369,7 +1418,7 @@ namespace QuickLauncher
{ {
// 获取鼠标位置下的控件 // 获取鼠标位置下的控件
Control control = shortcutsPanel.GetChildAtPoint(e.Location); Control control = shortcutsPanel.GetChildAtPoint(e.Location);
// 如果鼠标不在任何子控件上,则隐藏工具提示 // 如果鼠标不在任何子控件上,则隐藏工具提示
if (control == null) if (control == null)
{ {
@ -1418,6 +1467,7 @@ namespace QuickLauncher
} }
} }
// 启动应用程序
private void LaunchApplication(string path) private void LaunchApplication(string path)
{ {
try try
@ -1472,7 +1522,7 @@ namespace QuickLauncher
{ {
var json = File.ReadAllText(dataFilePath); var json = File.ReadAllText(dataFilePath);
categories = JsonSerializer.Deserialize<Dictionary<string, List<ShortcutItem>>>(json); categories = JsonSerializer.Deserialize<Dictionary<string, List<ShortcutItem>>>(json);
// 加载所有图标 // 加载所有图标
foreach (var category in categories.Values) foreach (var category in categories.Values)
{ {
@ -1481,8 +1531,19 @@ namespace QuickLauncher
item.LoadIcon(); item.LoadIcon();
} }
} }
RefreshCategoryList(); RefreshCategoryList();
// 如果有上次选择的分类,则选择它
if (!string.IsNullOrEmpty(settings.LastSelectedCategory) && categories.ContainsKey(settings.LastSelectedCategory))
{
SwitchCategory(settings.LastSelectedCategory);
}
// 否则选择第一个分类
else if (categories.Count > 0)
{
SwitchCategory(categories.Keys.First());
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -1497,8 +1558,33 @@ namespace QuickLauncher
categories["默认分类"] = new List<ShortcutItem>(); categories["默认分类"] = new List<ShortcutItem>();
SaveData(); SaveData();
RefreshCategoryList(); RefreshCategoryList();
SwitchCategory("默认分类");
} }
} }
private void SwitchCategory(string category)
{
currentCategory = category;
RefreshCategoryList();
ShowCategoryItems(category);
SaveSettings(); // 保存当前选择的分类
}
private void button1_Click(object sender, EventArgs e)
{
isDarkMode = !isDarkMode; // 切换主题状态
ApplyTheme(isDarkMode);
}
private void ApplyTheme(bool darkMode)
{
if (darkMode)
{
ChangeTheme(true);
}
else
ChangeTheme(false);
}
} }
public class ShortcutItem public class ShortcutItem