From f28fc0126ab8526cdd893674cdd689809ce46450 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sun, 26 May 2024 22:33:32 +0400 Subject: [PATCH] Fix saving settings after cancel --- DiscordSettings.Designer.cs | 8 -------- DiscordSettings.cs | 21 ++++++++++++++++++++- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/DiscordSettings.Designer.cs b/DiscordSettings.Designer.cs index b468ace..aff52eb 100644 --- a/DiscordSettings.Designer.cs +++ b/DiscordSettings.Designer.cs @@ -103,37 +103,29 @@ // // textDwhAvatarUrl // - this.textDwhAvatarUrl.DataBindings.Add(new System.Windows.Forms.Binding("Text", global::RelaunchProcess.Properties.Settings.Default, "dwhAvatarURL", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); this.textDwhAvatarUrl.Location = new System.Drawing.Point(9, 64); this.textDwhAvatarUrl.Name = "textDwhAvatarUrl"; this.textDwhAvatarUrl.Size = new System.Drawing.Size(337, 20); this.textDwhAvatarUrl.TabIndex = 7; - this.textDwhAvatarUrl.Text = global::RelaunchProcess.Properties.Settings.Default.dwhAvatarURL; // // textDwhBotName // - this.textDwhBotName.DataBindings.Add(new System.Windows.Forms.Binding("Text", global::RelaunchProcess.Properties.Settings.Default, "dwhBotname", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); this.textDwhBotName.Location = new System.Drawing.Point(9, 25); this.textDwhBotName.MaxLength = 40; this.textDwhBotName.Name = "textDwhBotName"; this.textDwhBotName.Size = new System.Drawing.Size(211, 20); this.textDwhBotName.TabIndex = 7; - this.textDwhBotName.Text = global::RelaunchProcess.Properties.Settings.Default.dwhBotname; // // textDwhURL // - this.textDwhURL.DataBindings.Add(new System.Windows.Forms.Binding("Text", global::RelaunchProcess.Properties.Settings.Default, "dwhURL", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); this.textDwhURL.Location = new System.Drawing.Point(9, 103); this.textDwhURL.Name = "textDwhURL"; this.textDwhURL.Size = new System.Drawing.Size(337, 20); this.textDwhURL.TabIndex = 3; - this.textDwhURL.Text = global::RelaunchProcess.Properties.Settings.Default.dwhURL; // // chbxDiscordEnabled // this.chbxDiscordEnabled.AutoSize = true; - this.chbxDiscordEnabled.Checked = global::RelaunchProcess.Properties.Settings.Default.dwhEnabled; - this.chbxDiscordEnabled.DataBindings.Add(new System.Windows.Forms.Binding("Checked", global::RelaunchProcess.Properties.Settings.Default, "dwhEnabled", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); this.chbxDiscordEnabled.Location = new System.Drawing.Point(9, 129); this.chbxDiscordEnabled.Name = "chbxDiscordEnabled"; this.chbxDiscordEnabled.Size = new System.Drawing.Size(232, 17); diff --git a/DiscordSettings.cs b/DiscordSettings.cs index 624c494..b645589 100644 --- a/DiscordSettings.cs +++ b/DiscordSettings.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; +using System.Drawing.Printing; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -17,6 +18,24 @@ namespace RelaunchProcess public DiscordSettings() { InitializeComponent(); + RestoreSettings(); + } + + private void RestoreSettings() + { + textDwhBotName.Text = Settings.Default.dwhBotname; + textDwhAvatarUrl.Text = Settings.Default.dwhAvatarURL; + textDwhURL.Text = Settings.Default.dwhURL; + chbxDiscordEnabled.Checked = Settings.Default.dwhEnabled; + } + + private void SaveSettings() + { + Settings.Default.dwhBotname = textDwhBotName.Text; + Settings.Default.dwhAvatarURL = textDwhAvatarUrl.Text; + Settings.Default.dwhURL = textDwhURL.Text; + Settings.Default.dwhEnabled = chbxDiscordEnabled.Checked; + Settings.Default.Save(); } private void BtnCancel_Click(object sender, EventArgs e) @@ -35,7 +54,7 @@ namespace RelaunchProcess { chbxDiscordEnabled.Checked = false; } - Settings.Default.Save(); + SaveSettings(); DialogResult = DialogResult.OK; Close(); }