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