From e687c78ba821a992259bc9a2ba13edafff8a694a Mon Sep 17 00:00:00 2001
From: unknown <2564608840@qq.com>
Date: Tue, 15 Jul 2025 20:30:10 +0800
Subject: [PATCH] =?UTF-8?q?add:=E8=87=AA=E5=AE=9A=E4=B9=89=E6=B5=AE?=
=?UTF-8?q?=E5=8A=A8=E6=A0=8F=E5=9B=BE=E6=A0=87?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Ink Canvas/MainWindow.xaml | 9 ++
Ink Canvas/MainWindow.xaml.cs | 2 +-
Ink Canvas/MainWindow_cs/MW_Settings.cs | 74 ++++++++++--
Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs | 47 ++------
Ink Canvas/Resources/Settings.cs | 21 ++++
Ink Canvas/Windows/AddCustomIconWindow.xaml | 44 +++++++
.../Windows/AddCustomIconWindow.xaml.cs | 113 ++++++++++++++++++
Ink Canvas/Windows/CustomIconWindow.xaml | 45 +++++++
Ink Canvas/Windows/CustomIconWindow.xaml.cs | 63 ++++++++++
9 files changed, 374 insertions(+), 44 deletions(-)
create mode 100644 Ink Canvas/Windows/AddCustomIconWindow.xaml
create mode 100644 Ink Canvas/Windows/AddCustomIconWindow.xaml.cs
create mode 100644 Ink Canvas/Windows/CustomIconWindow.xaml
create mode 100644 Ink Canvas/Windows/CustomIconWindow.xaml.cs
diff --git a/Ink Canvas/MainWindow.xaml b/Ink Canvas/MainWindow.xaml
index 78234815..3e6b94d7 100644
--- a/Ink Canvas/MainWindow.xaml
+++ b/Ink Canvas/MainWindow.xaml
@@ -1023,6 +1023,15 @@
+
+
+
+
+
+
diff --git a/Ink Canvas/MainWindow.xaml.cs b/Ink Canvas/MainWindow.xaml.cs
index 661ad4cf..cbd23036 100644
--- a/Ink Canvas/MainWindow.xaml.cs
+++ b/Ink Canvas/MainWindow.xaml.cs
@@ -226,7 +226,7 @@ namespace Ink_Canvas {
private void SystemEventsOnDisplaySettingsChanged(object sender, EventArgs e) {
if (!Settings.Advanced.IsEnableResolutionChangeDetection) return;
- ShowNotification($"检测到显示器信息变化,变为{System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width}x{System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height}");
+ ShowNotification($"检测到显示器信息变化,变为{System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width}x{System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height})");
new Thread(() => {
var isFloatingBarOutsideScreen = false;
var isInPPTPresentationMode = false;
diff --git a/Ink Canvas/MainWindow_cs/MW_Settings.cs b/Ink Canvas/MainWindow_cs/MW_Settings.cs
index cdec9763..069f94a0 100644
--- a/Ink Canvas/MainWindow_cs/MW_Settings.cs
+++ b/Ink Canvas/MainWindow_cs/MW_Settings.cs
@@ -243,41 +243,97 @@ namespace Ink_Canvas {
public void ComboBoxFloatingBarImg_SelectionChanged(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
Settings.Appearance.FloatingBarImg = ComboBoxFloatingBarImg.SelectedIndex;
- if (ComboBoxFloatingBarImg.SelectedIndex == 0) {
+ UpdateFloatingBarIcon();
+ SaveSettingsToFile();
+ }
+
+ public void UpdateFloatingBarIcon()
+ {
+ int index = Settings.Appearance.FloatingBarImg;
+
+ if (index == 0) {
FloatingbarHeadIconImg.Source =
new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/icc.png"));
FloatingbarHeadIconImg.Margin = new Thickness(0.5);
- } else if (ComboBoxFloatingBarImg.SelectedIndex == 1) {
+ } else if (index == 1) {
FloatingbarHeadIconImg.Source =
new BitmapImage(
new Uri("pack://application:,,,/Resources/Icons-png/icc-transparent-dark-small.png"));
FloatingbarHeadIconImg.Margin = new Thickness(1.2);
- } else if (ComboBoxFloatingBarImg.SelectedIndex == 2) {
+ } else if (index == 2) {
FloatingbarHeadIconImg.Source =
new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/kuandoujiyanhuaji.png"));
FloatingbarHeadIconImg.Margin = new Thickness(2, 2, 2, 1.5);
- } else if (ComboBoxFloatingBarImg.SelectedIndex == 3) {
+ } else if (index == 3) {
FloatingbarHeadIconImg.Source =
new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/kuanshounvhuaji.png"));
FloatingbarHeadIconImg.Margin = new Thickness(2, 2, 2, 1.5);
- } else if (ComboBoxFloatingBarImg.SelectedIndex == 4) {
+ } else if (index == 4) {
FloatingbarHeadIconImg.Source =
new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/kuanciya.png"));
FloatingbarHeadIconImg.Margin = new Thickness(2, 2, 2, 1.5);
- } else if (ComboBoxFloatingBarImg.SelectedIndex == 5) {
+ } else if (index == 5) {
FloatingbarHeadIconImg.Source =
new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/kuanneikuhuaji.png"));
FloatingbarHeadIconImg.Margin = new Thickness(2, 2, 2, 1.5);
- } else if (ComboBoxFloatingBarImg.SelectedIndex == 6) {
+ } else if (index == 6) {
FloatingbarHeadIconImg.Source =
new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/kuandogeyuanliangwo.png"));
FloatingbarHeadIconImg.Margin = new Thickness(2, 2, 2, 1.5);
- } else if (ComboBoxFloatingBarImg.SelectedIndex == 7) {
+ } else if (index == 7) {
FloatingbarHeadIconImg.Source =
new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/tiebahuaji.png"));
FloatingbarHeadIconImg.Margin = new Thickness(2, 2, 2, 1);
+ } else if (index >= 8 && index - 8 < Settings.Appearance.CustomFloatingBarImgs.Count) {
+ // 使用自定义图标
+ var customIcon = Settings.Appearance.CustomFloatingBarImgs[index - 8];
+ try {
+ FloatingbarHeadIconImg.Source = new BitmapImage(new Uri(customIcon.FilePath));
+ FloatingbarHeadIconImg.Margin = new Thickness(2);
+ } catch {
+ // 如果加载失败,使用默认图标
+ FloatingbarHeadIconImg.Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/icc.png"));
+ FloatingbarHeadIconImg.Margin = new Thickness(0.5);
+ }
}
- SaveSettingsToFile();
+ }
+
+ public void UpdateCustomIconsInComboBox()
+ {
+ // 保留前8个内置图标选项
+ while (ComboBoxFloatingBarImg.Items.Count > 8)
+ {
+ ComboBoxFloatingBarImg.Items.RemoveAt(ComboBoxFloatingBarImg.Items.Count - 1);
+ }
+
+ // 添加自定义图标选项
+ foreach (var customIcon in Settings.Appearance.CustomFloatingBarImgs)
+ {
+ ComboBoxItem item = new ComboBoxItem();
+ item.Content = customIcon.Name;
+ item.FontFamily = new System.Windows.Media.FontFamily("Microsoft YaHei UI");
+ ComboBoxFloatingBarImg.Items.Add(item);
+ }
+ }
+
+ private void ButtonAddCustomIcon_Click(object sender, RoutedEventArgs e)
+ {
+ AddCustomIconWindow dialog = new AddCustomIconWindow(this);
+ dialog.Owner = this;
+ dialog.ShowDialog();
+
+ if (dialog.IsSuccess)
+ {
+ // 自动选中新添加的图标
+ ComboBoxFloatingBarImg.SelectedIndex = ComboBoxFloatingBarImg.Items.Count - 1;
+ }
+ }
+
+ private void ButtonManageCustomIcons_Click(object sender, RoutedEventArgs e)
+ {
+ CustomIconWindow dialog = new CustomIconWindow(this);
+ dialog.Owner = this;
+ dialog.ShowDialog();
}
private void ToggleSwitchEnableTimeDisplayInWhiteboardMode_Toggled(object sender, RoutedEventArgs e) {
diff --git a/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs b/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs
index d8a9c871..48f9befc 100644
--- a/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs
+++ b/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs
@@ -247,41 +247,20 @@ namespace Ink_Canvas {
new SolidColorBrush(StringToColor("#FF555555"));
}
- ComboBoxFloatingBarImg.SelectedIndex = Settings.Appearance.FloatingBarImg;
- if (ComboBoxFloatingBarImg.SelectedIndex == 0) {
- FloatingbarHeadIconImg.Source =
- new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/icc.png"));
- FloatingbarHeadIconImg.Margin = new Thickness(0.5);
- } else if (ComboBoxFloatingBarImg.SelectedIndex == 1) {
- FloatingbarHeadIconImg.Source =
- new BitmapImage(
- new Uri("pack://application:,,,/Resources/Icons-png/icc-transparent-dark-small.png"));
- FloatingbarHeadIconImg.Margin = new Thickness(1.2);
- } else if (ComboBoxFloatingBarImg.SelectedIndex == 2) {
- FloatingbarHeadIconImg.Source =
- new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/kuandoujiyanhuaji.png"));
- FloatingbarHeadIconImg.Margin = new Thickness(2, 2, 2, 1.5);
- } else if (ComboBoxFloatingBarImg.SelectedIndex == 3) {
- FloatingbarHeadIconImg.Source =
- new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/kuanshounvhuaji.png"));
- FloatingbarHeadIconImg.Margin = new Thickness(2, 2, 2, 1.5);
- } else if (ComboBoxFloatingBarImg.SelectedIndex == 4) {
- FloatingbarHeadIconImg.Source =
- new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/kuanciya.png"));
- FloatingbarHeadIconImg.Margin = new Thickness(2, 2, 2, 1.5);
- } else if (ComboBoxFloatingBarImg.SelectedIndex == 5) {
- FloatingbarHeadIconImg.Source =
- new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/kuanneikuhuaji.png"));
- FloatingbarHeadIconImg.Margin = new Thickness(2, 2, 2, 1.5);
- } else if (ComboBoxFloatingBarImg.SelectedIndex == 6) {
- FloatingbarHeadIconImg.Source =
- new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/kuandogeyuanliangwo.png"));
- FloatingbarHeadIconImg.Margin = new Thickness(2, 2, 2, 1.5);
- } else if (ComboBoxFloatingBarImg.SelectedIndex == 7) {
- FloatingbarHeadIconImg.Source =
- new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/tiebahuaji.png"));
- FloatingbarHeadIconImg.Margin = new Thickness(2, 2, 2, 1);
+ // 更新自定义图标下拉列表
+ UpdateCustomIconsInComboBox();
+
+ // 设置选中的图标索引
+ // 如果索引超出范围(自定义图标可能已删除),使用默认图标
+ if (Settings.Appearance.FloatingBarImg >= ComboBoxFloatingBarImg.Items.Count)
+ {
+ Settings.Appearance.FloatingBarImg = 0;
}
+
+ ComboBoxFloatingBarImg.SelectedIndex = Settings.Appearance.FloatingBarImg;
+
+ // 更新浮动栏图标
+ UpdateFloatingBarIcon();
ToggleSwitchEnableTimeDisplayInWhiteboardMode.IsOn =
Settings.Appearance.EnableTimeDisplayInWhiteboardMode;
diff --git a/Ink Canvas/Resources/Settings.cs b/Ink Canvas/Resources/Settings.cs
index f9862226..a19bc9ac 100644
--- a/Ink Canvas/Resources/Settings.cs
+++ b/Ink Canvas/Resources/Settings.cs
@@ -1,5 +1,6 @@
using Newtonsoft.Json;
using System.IO;
+using System.Collections.Generic;
namespace Ink_Canvas
{
@@ -139,6 +140,8 @@ namespace Ink_Canvas
public double ViewboxFloatingBarScaleTransformValue { get; set; } = 1.0;
[JsonProperty("floatingBarImg")]
public int FloatingBarImg { get; set; } = 0;
+ [JsonProperty("customFloatingBarImgs")]
+ public List CustomFloatingBarImgs { get; set; } = new List();
[JsonProperty("viewboxFloatingBarOpacityValue")]
public double ViewboxFloatingBarOpacityValue { get; set; } = 1.0;
[JsonProperty("enableTrayIcon")]
@@ -438,4 +441,22 @@ namespace Ink_Canvas
[JsonProperty("directCallCiRand")]
public bool DirectCallCiRand { get; set; } = false;
}
+
+ public class CustomFloatingBarIcon
+ {
+ [JsonProperty("name")]
+ public string Name { get; set; }
+
+ [JsonProperty("filePath")]
+ public string FilePath { get; set; }
+
+ public CustomFloatingBarIcon(string name, string filePath)
+ {
+ Name = name;
+ FilePath = filePath;
+ }
+
+ // 用于JSON序列化
+ public CustomFloatingBarIcon() { }
+ }
}
diff --git a/Ink Canvas/Windows/AddCustomIconWindow.xaml b/Ink Canvas/Windows/AddCustomIconWindow.xaml
new file mode 100644
index 00000000..d20264e2
--- /dev/null
+++ b/Ink Canvas/Windows/AddCustomIconWindow.xaml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ink Canvas/Windows/AddCustomIconWindow.xaml.cs b/Ink Canvas/Windows/AddCustomIconWindow.xaml.cs
new file mode 100644
index 00000000..c429e5ed
--- /dev/null
+++ b/Ink Canvas/Windows/AddCustomIconWindow.xaml.cs
@@ -0,0 +1,113 @@
+using System;
+using System.IO;
+using System.Windows;
+using System.Windows.Media.Imaging;
+using Microsoft.Win32;
+
+namespace Ink_Canvas
+{
+ ///
+ /// AddCustomIconWindow.xaml 的交互逻辑
+ ///
+ public partial class AddCustomIconWindow : Window
+ {
+ private MainWindow mainWindow;
+ private string selectedFilePath;
+ public bool IsSuccess { get; private set; }
+
+ public AddCustomIconWindow(MainWindow owner)
+ {
+ InitializeComponent();
+ mainWindow = owner;
+ IsSuccess = false;
+
+ // 添加TextBox内容变化事件以检查是否可以保存
+ IconNameTextBox.TextChanged += (s, e) => ValidateSaveButton();
+ }
+
+ private void BrowseButton_Click(object sender, RoutedEventArgs e)
+ {
+ OpenFileDialog openFileDialog = new OpenFileDialog
+ {
+ Filter = "图像文件|*.png;*.jpg;*.jpeg;*.bmp;*.gif;*.ico",
+ Title = "选择一个图标文件"
+ };
+
+ if (openFileDialog.ShowDialog() == true)
+ {
+ selectedFilePath = openFileDialog.FileName;
+ IconPathTextBox.Text = selectedFilePath;
+
+ // 显示预览
+ try
+ {
+ BitmapImage bitmap = new BitmapImage();
+ bitmap.BeginInit();
+ bitmap.UriSource = new Uri(selectedFilePath);
+ bitmap.EndInit();
+ IconPreviewImage.Source = bitmap;
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show($"无法加载图像: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
+ }
+
+ // 自动填充名称建议(文件名,不包括扩展名)
+ string suggestedName = Path.GetFileNameWithoutExtension(selectedFilePath);
+ IconNameTextBox.Text = suggestedName;
+
+ ValidateSaveButton();
+ }
+ }
+
+ private void ValidateSaveButton()
+ {
+ SaveButton.IsEnabled = !string.IsNullOrWhiteSpace(IconNameTextBox.Text) && !string.IsNullOrEmpty(selectedFilePath);
+ }
+
+ private void CancelButton_Click(object sender, RoutedEventArgs e)
+ {
+ this.Close();
+ }
+
+ private void SaveButton_Click(object sender, RoutedEventArgs e)
+ {
+ try
+ {
+ // 创建pictures文件夹(如果不存在)
+ string picturesFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "pictures");
+ if (!Directory.Exists(picturesFolder))
+ {
+ Directory.CreateDirectory(picturesFolder);
+ }
+
+ // 生成一个唯一的文件名(使用GUID)
+ string extension = Path.GetExtension(selectedFilePath);
+ string newFileName = $"{Guid.NewGuid()}{extension}";
+ string destPath = Path.Combine(picturesFolder, newFileName);
+
+ // 复制文件到pictures文件夹
+ File.Copy(selectedFilePath, destPath);
+
+ // 创建新的自定义图标对象
+ var customIcon = new CustomFloatingBarIcon(IconNameTextBox.Text, destPath);
+
+ // 添加到主窗口的设置中
+ MainWindow.Settings.Appearance.CustomFloatingBarImgs.Add(customIcon);
+
+ // 更新ComboBox
+ mainWindow.UpdateCustomIconsInComboBox();
+
+ // 保存设置
+ MainWindow.SaveSettingsToFile();
+
+ IsSuccess = true;
+ this.Close();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show($"保存图标时出错: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Ink Canvas/Windows/CustomIconWindow.xaml b/Ink Canvas/Windows/CustomIconWindow.xaml
new file mode 100644
index 00000000..e9524aa1
--- /dev/null
+++ b/Ink Canvas/Windows/CustomIconWindow.xaml
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ink Canvas/Windows/CustomIconWindow.xaml.cs b/Ink Canvas/Windows/CustomIconWindow.xaml.cs
new file mode 100644
index 00000000..c4f30596
--- /dev/null
+++ b/Ink Canvas/Windows/CustomIconWindow.xaml.cs
@@ -0,0 +1,63 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Windows;
+using System.Windows.Controls;
+
+namespace Ink_Canvas
+{
+ ///
+ /// CustomIconWindow.xaml 的交互逻辑
+ ///
+ public partial class CustomIconWindow : Window
+ {
+ private MainWindow mainWindow;
+ public ObservableCollection CustomIcons { get; set; }
+
+ public CustomIconWindow(MainWindow owner)
+ {
+ InitializeComponent();
+ mainWindow = owner;
+
+ // 从主窗口的设置获取自定义图标列表
+ CustomIcons = new ObservableCollection(MainWindow.Settings.Appearance.CustomFloatingBarImgs);
+ CustomIconsListView.ItemsSource = CustomIcons;
+ }
+
+ private void DeleteCustomIcon_Click(object sender, RoutedEventArgs e)
+ {
+ if (sender is Button button && button.Tag is CustomFloatingBarIcon icon)
+ {
+ // 从列表中移除图标
+ CustomIcons.Remove(icon);
+
+ // 更新主窗口的设置
+ MainWindow.Settings.Appearance.CustomFloatingBarImgs.Clear();
+ foreach (var customIcon in CustomIcons)
+ {
+ MainWindow.Settings.Appearance.CustomFloatingBarImgs.Add(customIcon);
+ }
+
+ // 如果当前选中的是被删除的图标,重置为默认图标
+ if (MainWindow.Settings.Appearance.FloatingBarImg >= 8 &&
+ MainWindow.Settings.Appearance.FloatingBarImg - 8 >= MainWindow.Settings.Appearance.CustomFloatingBarImgs.Count)
+ {
+ MainWindow.Settings.Appearance.FloatingBarImg = 0;
+ mainWindow.ComboBoxFloatingBarImg.SelectedIndex = 0;
+ mainWindow.UpdateFloatingBarIcon();
+ }
+
+ // 更新ComboBox
+ mainWindow.UpdateCustomIconsInComboBox();
+
+ // 保存设置
+ MainWindow.SaveSettingsToFile();
+ }
+ }
+
+ private void CloseButton_Click(object sender, RoutedEventArgs e)
+ {
+ this.Close();
+ }
+ }
+}
\ No newline at end of file