// User checked the "Ask me before drive can be disconnected box" private void checkBoxAskMe_CheckedChanged(object sender, EventArgs e) { if (checkBoxAskMe.Checked) { // Is QueryRemove enabled? // If not, we will enable it for the drive which is selected // in the listbox. // If the listbox is empty, no drive has been detected yet so do nothing now. if (!driveDetector.IsQueryHooked && comboBox1.Items.Count > 0) { if (comboBox1.SelectedItem == null) { //MessageBox.Show("Please choose the drive for which you wish to be asked in the list (select its message)."); MessageBox.Show("Please choose the drive from the list"); // checkBoxAskMe.Checked = false; return; } bool ok = false; string s = (string)comboBox1.Text; int n = s.IndexOf(':'); if (n > 0) { s = s.Substring(n - 1, 3); // Gets drive letter from the message, (e.g. "E:\\") // Tell DriveDetector to monitor this drive ok = driveDetector.EnableQueryRemove(s); } if (!ok) { MessageBox.Show("Sorry, for some reason notification for QueryRemove did not work out."); } } } else { // "unchecked" the box so disable query remove message if (driveDetector.IsQueryHooked) { driveDetector.DisableQueryRemove(); } } }