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/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/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(); // 保存为默认设置 + } } 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)