private void _customizeProcessMenuItem_Click(object sender, EventArgs e) { using (SelectProcess selectProc = new SelectProcess()) { if (DialogResult.OK == selectProc.ShowDialog()) { foreach (ListViewItem item in _perProcessListView.Items) { if (string.Equals(item.Text, selectProc.ProcessName, StringComparison.InvariantCultureIgnoreCase)) { MessageBox.Show("Sepcified process already exists.", "Process Exists", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); return; } } GeneralSettings customSettings = new GeneralSettings(); customSettings.Load(string.Format(@"{0}\{1}\{2}", GScrollRegistry.GScrollKey, GScrollRegistry.PerProcessKey, selectProc.ProcessName), true); using (GeneralSettingsHost host = new GeneralSettingsHost()) { if (DialogResult.OK == host.ShowDialog(string.Format("Settings for {0}", selectProc.ProcessName), customSettings)) { // add the list item here ListViewItem item = new ListViewItem(selectProc.ProcessName); item.Tag = customSettings; _perProcessListView.Items.Add(item); } else { customSettings.Dispose(); } } } } }
private void _editProcessMenuItem_Click(object sender, EventArgs e) { if (_perProcessListView.SelectedIndices.Count > 0) { ListViewItem item = _perProcessListView.Items[_perProcessListView.SelectedIndices[0]]; // show a dialog here to create GeneralSettings customSettings = null; if (null != item.Tag) { customSettings = item.Tag as GeneralSettings; } else { customSettings = new GeneralSettings(); customSettings.Load(string.Format(@"{0}\{1}\{2}", GScrollRegistry.GScrollKey, GScrollRegistry.PerProcessKey, item.Text), false); item.Tag = customSettings; } using (GeneralSettingsHost host = new GeneralSettingsHost()) { host.ShowDialog(string.Format("Settings for {0}", item.Text), customSettings); } } }