private void btnDeleteProfile_Click(object sender, EventArgs e) { if (lbProfiles.SelectedIndex > -1) { // Make sure they are sure! if (MessageBox.Show("Are you sure you want to delete this profile?" + Environment.NewLine + "This cannot be undone!", "SpamGrabber", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { // See if this was one of the defaults Profile objProfile = UserProfiles.GetProfileByName(GetSelectedProfileName()); if (GlobalSettings.DefaultSpamProfileId.Equals(objProfile.Id)) { GlobalSettings.DefaultSpamProfileId = string.Empty; GlobalSettings.ResetDefaultProfile(GlobalSettings.DefaultType.Spam); } if (GlobalSettings.DefaultHamProfileId.Equals(objProfile.Id)) { GlobalSettings.DefaultHamProfileId = string.Empty; GlobalSettings.ResetDefaultProfile(GlobalSettings.DefaultType.Ham); } // Delete the profile UserProfiles.DeleteProfile(objProfile.Name); // Clear all required caches and fire update event UserProfiles.ClearProfileCache(); PopulateList(); ProfileListChanged(this); } } }