using System; using System.Collections.Generic; using System.ComponentModel; using System.Configuration; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace PDF_Merge { public partial class ConfForm : Form { public ConfForm() { InitializeComponent(); string sourcePath = ConfigurationManager.AppSettings["PDF-Path"]; string outputPath = ConfigurationManager.AppSettings["PDF-Output"]; sourceBox.Text = sourcePath; outputBox.Text = outputPath; if (ConfigurationManager.AppSettings["overwrite"] == true.ToString()) { overrideCBox.Checked = true; } else { overrideCBox.Checked = false; } } private void cancelBtn_Click(object sender, EventArgs e) { 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(); } private void sourceDirBtn_Click(object sender, EventArgs e) { using (var SourceDirPicker = new FolderBrowserDialog()) { if(SourceDirPicker.ShowDialog() == DialogResult.OK) { var sourceDir = SourceDirPicker.SelectedPath; sourceBox.Text = sourceDir; } } } } }