Configuration changes now saving properly.

This commit is contained in:
efrick 2024-08-05 13:41:30 -04:00
parent 0a132d75ec
commit 6d06fa90e5
2 changed files with 26 additions and 1 deletions

1
ConfForm.Designer.cs generated
View File

@ -50,6 +50,7 @@ namespace PDF_Merge
saveBtn.TabIndex = 0; saveBtn.TabIndex = 0;
saveBtn.Text = "Save"; saveBtn.Text = "Save";
saveBtn.UseVisualStyleBackColor = true; saveBtn.UseVisualStyleBackColor = true;
saveBtn.Click += saveBtn_Click;
// //
// cancelBtn // cancelBtn
// //

View File

@ -22,7 +22,7 @@ namespace PDF_Merge
sourceBox.Text = sourcePath; sourceBox.Text = sourcePath;
outputBox.Text = outputPath; outputBox.Text = outputPath;
if (ConfigurationManager.AppSettings["overwrite"] == "true") if (ConfigurationManager.AppSettings["overwrite"] == true.ToString())
{ {
overrideCBox.Checked = true; overrideCBox.Checked = true;
} }
@ -36,5 +36,29 @@ namespace PDF_Merge
{ {
this.Close(); 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();
}
} }
} }