private void watchNewFilesToolStripMenuItem_Click(object sender, EventArgs e) { if (settings.SourcePath.Length == 0) { MessageBox.Show( "Please select a source path in settings first.", "Unable to scan", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { // Invert the value to reflect the user's intention bool enabled = !watchNewFilesToolStripMenuItem.Checked; // Update the settings, the context menu checkbox, // and the FileSystemWatcher based on the checkbox state settings.ActiveScan = enabled; fileSystemWatcher1.EnableRaisingEvents = enabled; watchNewFilesToolStripMenuItem.Checked = enabled; // This is a change saved with settings FileScannerSettings.SaveSettings(settings); } }
private void closeButton_Click(object sender, EventArgs e) { // Copy choices back to settings object settings.SourcePath = this.sourceTextBox.Text; settings.RecursiveScan = this.recursiveScanCheckbox.Checked; // Copy appropriate settigns to FileSystemWatcher fileSystemWatcher1.Path = settings.SourcePath; fileSystemWatcher1.IncludeSubdirectories = settings.RecursiveScan; // Save the changes to disk for consistency FileScannerSettings.SaveSettings(settings); this.Visible = false; }