private void EditCusto_Click(object sender, EventArgs e) { if (dataCusto.SelectedRows.Count > 0) { //se localiza el formulario buscandolo entre los forms abiertos Form fnc = Application.OpenForms.Cast <Form>().FirstOrDefault(x => x is NewCustomers); if (fnc != null) { if (fnc.WindowState == FormWindowState.Minimized) { fnc.WindowState = FormWindowState.Normal; } //si la instancia existe la pongo en primer plano fnc.BringToFront(); return; } //sino existe la instancia se crea una nueva NewCustomers NC = new NewCustomers(); NC.txtCustoId.Text = dataCusto.CurrentRow.Cells[0].Value.ToString(); NC.txtCustoName.Text = dataCusto.CurrentRow.Cells[1].Value.ToString(); NC.txtCustoCed.Text = dataCusto.CurrentRow.Cells[2].Value.ToString(); NC.txtCustoAddress.Text = dataCusto.CurrentRow.Cells[3].Value.ToString(); NC.txtCustoPhone.Text = dataCusto.CurrentRow.Cells[4].Value.ToString(); NC.Show(); NC.FormClosed += new FormClosedEventHandler(NewCustomers_FormClosed); } else { MessageBox.Show("Select Row"); } }
private void NewCusto_Click(object sender, EventArgs e) { //se localiza el formulario buscandolo entre los forms abiertos Form fnc = Application.OpenForms.Cast <Form>().FirstOrDefault(x => x is NewCustomers); if (fnc != null) { if (fnc.WindowState == FormWindowState.Minimized) { fnc.WindowState = FormWindowState.Normal; } //si la instancia existe la pongo en primer plano fnc.BringToFront(); return; } //sino existe la instancia se crea una nueva NewCustomers NC = new NewCustomers(); NC.Show(); NC.FormClosed += new FormClosedEventHandler(NewCustomers_FormClosed); }