private void editContactToolStripMenuItem_Click(object sender, EventArgs e) { if (contactlist.SelectedItem != null) { option_add_contact lForm = new option_add_contact(); lForm.Owner = this;//重要的一步,主要是使Form2的Owner指針指向Form1 lForm.CMD = "edit"; lForm.contact = contactlist.SelectedItem.ToString(); lForm.ShowDialog(); if (reContact != null) { for (int i = 0; i < memoryData.contact.Count; i++) { Contactstruct tar = (Contactstruct)memoryData.contact[i]; if (tar.name == reContact) { contactName.Text = tar.name; contactMail.Text = tar.mail; contactPhone.Text = tar.phone; contactDescription.Text = tar.description; contactlist.SelectedItem = reContact; } } reContact = null; } } }
//↑↑↑↑↑↑↑↑↑↑ group list right menu ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ //↓↓↓↓↓↓↓↓↓↓ contact list right menu ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ private void addContactToolStripMenuItem_Click(object sender, EventArgs e) { option_add_contact lForm = new option_add_contact(); lForm.Owner = this;//重要的一步,主要是使Form2的Owner指針指向Form1 lForm.CMD = "add"; lForm.ShowDialog(); if (reContact != null) { contactlist.Items.Add(reContact); contactlist.SelectedItem = reContact; reContact = null; } }
private void editContact_Click(object sender, EventArgs e) { if (contactlist.SelectedItem != null) { option_add_contact lForm = new option_add_contact(); lForm.Owner = this;//重要的一步,主要是使Form2的Owner指針指向Form1 lForm.CMD = "edit"; lForm.contact = contactlist.SelectedItem.ToString(); lForm.ShowDialog(); if (reContact != null) { for (int i = 0; i < memoryData.contact.Count; i++) { Contactstruct tar = (Contactstruct)memoryData.contact[i]; if (tar.name == reContact) { contactName.Text = tar.name; contactMail.Text = tar.mail; contactPhone.Text = tar.phone; contactDescription.Text = tar.description; contactlist.SelectedItem = reContact; } } ContactGroup2 gptar = (ContactGroup2)memoryData.GroupContact2[0]; for (int cc = 0; cc < gptar.groupmember.Count; cc++) { Contactstruct edit = (Contactstruct)gptar.groupmember[cc]; if (edit.name == reContact) { edit.name = contactName.Text; edit.mail = contactMail.Text; edit.phone = contactPhone.Text; edit.description = contactDescription.Text; gptar.groupmember[cc] = edit; break; } } reContact = null; } } }