private async void OnEditProfileClick(object sender, EventArgs e) { var profileName = cmbProfiles.SelectedItem.ToString(); var profileIndex = cmbProfiles.SelectedIndex; var pf = ProfileForm.ShowDialog(this, "Profile name", "Edit Profile", profileName); if (pf.DialogResult != DialogResult.OK) { return; } if (!ValidateProfileName(pf.Value)) { btnEdit.PerformClick(); return; } var result = await _profileManager.EditProfileAsync(profileName, pf.Value); if (!result) { MessageBox.Show("An error occurred while editing profile.", "Edit Profile Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } cmbProfiles.Items[profileIndex] = pf.Value; }
public static ProfileForm ShowDialog(IWin32Window owner, string message, string caption, string defaultValue) { var form = new ProfileForm { Text = caption, lblMessage = { Text = message }, txtValue = { Text = defaultValue } }; form.ShowDialog(owner); return(form); }
private async void OnNewProfileClick(object sender, EventArgs e) { var pf = ProfileForm.ShowDialog(this, "Profile name", "New Profile"); if (pf.DialogResult != DialogResult.OK) { return; } if (!ValidateProfileName(pf.Value)) { btnNew.PerformClick(); return; } await _profileManager.CreateProfileAsync(pf.Value); cmbProfiles.Items.Add(pf.Value); cmbProfiles.SelectedItem = pf.Value; }