private void btnAddSource_Click(object sender, EventArgs e) { Form f = Application.OpenForms["FormAddSource"]; //查找是否打开过Form1窗体 if (f == null) { FormAddSource formAddSource = new FormAddSource("add", mycon, this, new Source()); formAddSource.Show(); } else { f.Focus(); } }
private void btnEditSource_Click(object sender, EventArgs e) { Source source = new Source(); source.id = int.Parse(dgvSource.SelectedRows[0].Cells[3].Value.ToString()); source.name = dgvSource.SelectedRows[0].Cells[1].Value.ToString(); source.pic = dgvSource.SelectedRows[0].Cells[2].Value.ToString(); source.sort = int.Parse(dgvSource.SelectedRows[0].Cells[0].Value.ToString()); Form f = Application.OpenForms["FormAddSource"]; //查找是否打开过Form1窗体 if (f == null) { FormAddSource formAddSource = new FormAddSource("edit", mycon, this, source); formAddSource.Show(); } else { f.Focus(); } }