private void SettingButtonClick(object Sender, EventArgs e) { // Find the corresponding button details. int i = 0; while ((i < settingButtonProperties.Length) && ((settingButtonProperties[i] == null) || (settingButtonProperties[i].button != Sender))) { i++; } if (i >= settingButtonProperties.Length) { throw new Exception("Unable to find setting button properties"); } // Take the appropriate action. Setting setting = settings[i]; switch (setting.Type) { case "openfile": case "savefile": { FileDialogData data = (FileDialogData)settingButtonProperties[i].data; FileDialog dialog = setting.Type == "openfile" ? (FileDialog)(new OpenFileDialog()) : (FileDialog)(new SaveFileDialog()); dialog.FileName = controls[i].Text; dialog.Filter = data.filter; dialog.FilterIndex = data.filterIndex; dialog.InitialDirectory = data.initialDir; if (dialog.ShowDialog() == DialogResult.OK) { controls[i].Text = dialog.FileName; } break; } case "exefile": { FormFileTreeView dialog = new FormFileTreeView(); dialog.FileName = controls[i].Text; if (dialog.ShowDialog() == DialogResult.OK) { controls[i].Text = dialog.FileName; } break; } case "comportin": case "comportout": { FormComSelect dialog = new FormComSelect(); dialog.ComPortSpec = settingButtonProperties[i].data.ToString(); dialog.IsInputPort = setting.Type == "comportin"; if (dialog.ShowDialog() == DialogResult.OK) { settingButtonProperties[i].data = dialog.ComPortSpec; controls[i].Text = GetComPortDescription(settingButtonProperties[i].data.ToString()); } break; } default: throw new Exception("Invalid setting type: " + setting.Type); } }
private void SettingButtonClick(object Sender, EventArgs e) { // Find the corresponding button details. int i = 0; while ((i < settingButtonProperties.Length) && ((settingButtonProperties[i] == null) || (settingButtonProperties[i].button != Sender))) i++; if (i >= settingButtonProperties.Length) throw new Exception("Unable to find setting button properties"); // Take the appropriate action. Setting setting = settings[i]; switch (setting.Type) { case "openfile": case "savefile": { FileDialogData data = (FileDialogData)settingButtonProperties[i].data; FileDialog dialog = setting.Type == "openfile" ? (FileDialog)(new OpenFileDialog()) : (FileDialog)(new SaveFileDialog()); dialog.FileName = controls[i].Text; dialog.Filter = data.filter; dialog.FilterIndex = data.filterIndex; dialog.InitialDirectory = data.initialDir; if (dialog.ShowDialog() == DialogResult.OK) controls[i].Text = dialog.FileName; break; } case "exefile": { FormFileTreeView dialog = new FormFileTreeView(); dialog.FileName = controls[i].Text; if (dialog.ShowDialog() == DialogResult.OK) controls[i].Text = dialog.FileName; break; } case "comportin": case "comportout": { FormComSelect dialog = new FormComSelect(); dialog.ComPortSpec = settingButtonProperties[i].data.ToString(); dialog.IsInputPort = setting.Type == "comportin"; if (dialog.ShowDialog() == DialogResult.OK) { settingButtonProperties[i].data = dialog.ComPortSpec; controls[i].Text = GetComPortDescription(settingButtonProperties[i].data.ToString()); } break; } default: throw new Exception("Invalid setting type: " + setting.Type); } }