diff --git a/ConfForm.Designer.cs b/ConfForm.Designer.cs index 77869db..ccd382b 100644 --- a/ConfForm.Designer.cs +++ b/ConfForm.Designer.cs @@ -50,6 +50,7 @@ namespace PDF_Merge saveBtn.TabIndex = 0; saveBtn.Text = "Save"; saveBtn.UseVisualStyleBackColor = true; + saveBtn.Click += saveBtn_Click; // // cancelBtn // diff --git a/ConfForm.cs b/ConfForm.cs index c558cef..652f423 100644 --- a/ConfForm.cs +++ b/ConfForm.cs @@ -22,7 +22,7 @@ namespace PDF_Merge sourceBox.Text = sourcePath; outputBox.Text = outputPath; - if (ConfigurationManager.AppSettings["overwrite"] == "true") + if (ConfigurationManager.AppSettings["overwrite"] == true.ToString()) { overrideCBox.Checked = true; } @@ -36,5 +36,29 @@ namespace PDF_Merge { this.Close(); } + + private void saveBtn_Click(object sender, EventArgs e) + { + Configuration appConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); + AppSettingsSection appSettings = appConfig.AppSettings; + if (sourceBox.Text.Length > 0) + { + appSettings.Settings["PDF-Path"].Value = sourceBox.Text; + } else + { + MessageBox.Show("Source path cannot be empty.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + if (outputBox.Text.Length > 0) + { + appSettings.Settings["PDF-Output"].Value = outputBox.Text; + } else + { + MessageBox.Show("Output path cannot be empty.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + appSettings.Settings["overwrite"].Value = overrideCBox.Checked.ToString(); + appConfig.Save(ConfigurationSaveMode.Modified); + ConfigurationManager.RefreshSection("appSettings"); + this.Close(); + } } }