From 25d5a9cebc00a1b5094ce671762771adc5239c45 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 19 Jan 2026 03:06:48 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BE=BF=E7=AD=BE?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E6=8C=81=E4=B9=85=E5=8C=96=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 功能说明: - 新建便签时自动应用上一次设置的字体样式、主题颜色、不透明度等 - 用户修改任何样式设置时,自动保存为默认设置 - 下次创建新便签时,将使用这些保存的默认设置 实现细节: 1. 新增 DefaultNoteSettings 类用于保存默认设置 2. 在 REGISTRY 类中添加 SaveDefaultSettings 和 GetDefaultSettings 方法 3. 修改 MainForm.LoadData 方法,新建便签时应用保存的默认设置 4. 新增 MainForm.SaveAsDefaultSettings 方法 5. 在所有样式修改点调用 SaveAsDefaultSettings 保存设置: - 主题变更(CurrentTheme setter) - 样式变更(CurrentStyle setter) - 不透明度变更(opacity_val_ValueChanged) - 自定义主题颜色变更(topbar_color_Click, back_color_Click, text_color_Click) - 自定义字体变更(current_font_Click, font_size_ValueChanged) 修改文件: - FormData.cs: 添加 DefaultNoteSettings 类 - REGISTRY.cs: 添加默认设置的保存/读取方法 - MainForm.cs: 修改 LoadData 方法,添加 SaveAsDefaultSettings 方法 - SettingForm.cs: 在样式修改事件中调用 SaveAsDefaultSettings --- Desktop Notes/Desktop Notes/FormData.cs | 20 ++++++++ Desktop Notes/Desktop Notes/MainForm.cs | 56 ++++++++++++++++++---- Desktop Notes/Desktop Notes/REGISTRY.cs | 29 +++++++++++ Desktop Notes/Desktop Notes/SettingForm.cs | 10 +++- 4 files changed, 103 insertions(+), 12 deletions(-) diff --git a/Desktop Notes/Desktop Notes/FormData.cs b/Desktop Notes/Desktop Notes/FormData.cs index 384c65b..ecaf3ec 100644 --- a/Desktop Notes/Desktop Notes/FormData.cs +++ b/Desktop Notes/Desktop Notes/FormData.cs @@ -90,4 +90,24 @@ private void DefaultStyle() FStyle = FontStyle.Regular; } } + + // 默认便签设置类,用于保存上一次使用的样式设置 + public class DefaultNoteSettings + { + public int theme { get; set; } + public int style { get; set; } + public double opacity { get; set; } + public Theme customTheme { get; set; } + public Style customStyle { get; set; } + + public DefaultNoteSettings() + { + // 设置初始默认值 + theme = 1; // 默认主题 + style = 1; // 默认样式 + opacity = 0.95; // 默认不透明度 + customTheme = new Theme(); + customStyle = new Style(); + } + } } diff --git a/Desktop Notes/Desktop Notes/MainForm.cs b/Desktop Notes/Desktop Notes/MainForm.cs index d9e6675..08c0ccc 100644 --- a/Desktop Notes/Desktop Notes/MainForm.cs +++ b/Desktop Notes/Desktop Notes/MainForm.cs @@ -40,24 +40,46 @@ public MainForm(int id, FormData dat = null) private void LoadData(FormData dat = null) { //load defaults - this.Opacity = 0.95; this.StartPosition = FormStartPosition.WindowsDefaultLocation; this.CreationTime = DateTime.Now; if (string.IsNullOrEmpty(Title)) { Title = string.Format("Note {0:##}", FORM_ID); } - if (Program.Themes.Count > 1) - { - Random rand = new Random(); - CurrentTheme = rand.Next(Program.Themes.Count - 1) + 1; - } - if (Program.Styles.Count > 1) - { - CurrentStyle = 1; - } + + // 如果是新建便签,应用上次保存的默认设置 if (dat == null) { + DefaultNoteSettings defaultSettings = REGISTRY.GetDefaultSettings(); + this.Opacity = defaultSettings.opacity; + + if (defaultSettings.customTheme != null) + { + this.CustomTheme = defaultSettings.customTheme; + } + if (defaultSettings.customStyle != null) + { + this.CustomStyle = defaultSettings.customStyle; + } + + if (Program.Themes.Count > defaultSettings.theme) + { + CurrentTheme = defaultSettings.theme; + } + else if (Program.Themes.Count > 1) + { + CurrentTheme = 1; + } + + if (Program.Styles.Count > defaultSettings.style) + { + CurrentStyle = defaultSettings.style; + } + else if (Program.Styles.Count > 1) + { + CurrentStyle = 1; + } + this.Show(); return; } @@ -110,6 +132,7 @@ public int CurrentTheme Save(); } ReloadTheme(); + SaveAsDefaultSettings(); // 保存为默认设置 } } @@ -129,9 +152,22 @@ public int CurrentStyle Save(); } ReloadStyle(); + SaveAsDefaultSettings(); // 保存为默认设置 } } + // 保存当前便签的样式设置为默认设置 + public void SaveAsDefaultSettings() + { + DefaultNoteSettings settings = new DefaultNoteSettings(); + settings.theme = this.CurrentTheme; + settings.style = this.CurrentStyle; + settings.opacity = this.Opacity; + settings.customTheme = this.CustomTheme; + settings.customStyle = this.CustomStyle; + REGISTRY.SaveDefaultSettings(settings); + } + public void ReloadTheme() { Theme th = Program.Themes[_theme]; diff --git a/Desktop Notes/Desktop Notes/REGISTRY.cs b/Desktop Notes/Desktop Notes/REGISTRY.cs index 09f9b16..24ad7e0 100644 --- a/Desktop Notes/Desktop Notes/REGISTRY.cs +++ b/Desktop Notes/Desktop Notes/REGISTRY.cs @@ -75,5 +75,34 @@ public static bool FirstRun return false; } } + + // 默认便签设置的注册表键名 + private const string DEFAULT_SETTINGS_KEY = "_DefaultSettings"; + + // 保存默认便签设置 + public static void SaveDefaultSettings(DefaultNoteSettings settings) + { + try + { + string json = JsonConvert.SerializeObject(settings); + REG_PATH.SetValue(DEFAULT_SETTINGS_KEY, json); + } + catch { } + } + + // 读取默认便签设置 + public static DefaultNoteSettings GetDefaultSettings() + { + try + { + object dat = REG_PATH.GetValue(DEFAULT_SETTINGS_KEY, null); + if (dat == null) return new DefaultNoteSettings(); + return JsonConvert.DeserializeObject((string)dat); + } + catch + { + return new DefaultNoteSettings(); + } + } } } diff --git a/Desktop Notes/Desktop Notes/SettingForm.cs b/Desktop Notes/Desktop Notes/SettingForm.cs index 5cd6f34..980c93f 100644 --- a/Desktop Notes/Desktop Notes/SettingForm.cs +++ b/Desktop Notes/Desktop Notes/SettingForm.cs @@ -110,7 +110,7 @@ private void style_sel_SelectedIndexChanged(object sender, EventArgs e) catch { } } - //change values + //change values private void current_font_Click(object sender, EventArgs e) { FontDialog fod = new FontDialog(); @@ -130,6 +130,7 @@ private void current_font_Click(object sender, EventArgs e) form.Save(); setstyle(); } + form.SaveAsDefaultSettings(); // 保存为默认设置 } } @@ -150,6 +151,7 @@ private void font_size_ValueChanged(object sender, EventArgs e) form.Save(); setstyle(); } + form.SaveAsDefaultSettings(); // 保存为默认设置 } private void trackBar1_Scroll(object sender, EventArgs e) @@ -163,6 +165,7 @@ private void opacity_val_ValueChanged(object sender, EventArgs e) form.Opacity = (double)opacity_val.Value; int v = (int)(opacity_val.Value * 100); if (v >= trackBar1.Minimum && v != trackBar1.Value) trackBar1.Value = v; + form.SaveAsDefaultSettings(); // 保存为默认设置 } //change custom themes @@ -183,6 +186,7 @@ private void topbar_color_Click(object sender, EventArgs e) form.Save(); settheme(); } + form.SaveAsDefaultSettings(); // 保存为默认设置 } } @@ -203,6 +207,7 @@ private void back_color_Click(object sender, EventArgs e) form.Save(); settheme(); } + form.SaveAsDefaultSettings(); // 保存为默认设置 } } @@ -223,7 +228,8 @@ private void text_color_Click(object sender, EventArgs e) form.Save(); settheme(); } - } + form.SaveAsDefaultSettings(); // 保存为默认设置 + } } From 0f5e10789931d80be0ad37dc4ce488c2a1162d9e Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 19 Jan 2026 03:11:58 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7=E8=87=B3=20v1.3.0=20=E5=B9=B6=E6=9B=B4=E6=96=B0=20REA?= =?UTF-8?q?DME?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 版本号从 1.1.0/1.2.0 统一更新为 1.3.0.0 - README 中添加新功能说明:样式记忆功能 --- Desktop Notes/Desktop Notes/Properties/AssemblyInfo.cs | 8 ++++---- README.md | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Desktop Notes/Desktop Notes/Properties/AssemblyInfo.cs b/Desktop Notes/Desktop Notes/Properties/AssemblyInfo.cs index 1542c6c..8615c4d 100644 --- a/Desktop Notes/Desktop Notes/Properties/AssemblyInfo.cs +++ b/Desktop Notes/Desktop Notes/Properties/AssemblyInfo.cs @@ -24,12 +24,12 @@ // Version information for an assembly consists of the following four values: // // Major Version -// Minor Version +// Minor Version // Build Number // Revision // -// You can specify all the values or you can default the Build and Revision Numbers +// You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.1.0.0")] -[assembly: AssemblyFileVersion("1.2.0.0")] +[assembly: AssemblyVersion("1.3.0.0")] +[assembly: AssemblyFileVersion("1.3.0.0")] diff --git a/README.md b/README.md index 145b7c9..615809f 100644 --- a/README.md +++ b/README.md @@ -9,4 +9,6 @@ Desktop-Notes 支持始终置顶,开机启动,主题设置等 +**v1.3.0 新增功能:** 样式记忆功能 - 新建便签自动应用上次设置的字体、颜色、透明度 + ![image](https://github.com/user-attachments/assets/7f0b28cc-168f-41ff-a884-11290ebdab32)