po1725 Posted February 23, 2014 at 07:37 PM Report #546395 Posted February 23, 2014 at 07:37 PM (edited) Boa noite! Tenho FormA e FormB e não estou a conseguir nenhum método eficaz para fechar um FormB a partir do FormA, alguém me pode ajudar? já tentei os seguintes códigos: private void btnFecharForm_Click(object sender, EventArgs e) { FormB[] forms = Application.OpenForms.Cast<FormB>().ToArray(); foreach (FormB thisForm in forms) { if (thisForm.Name != "FormB") thisForm.Close(); } } FormB fb= (FormB )Application.OpenForms["FormB"]; fb.Close(); for (int index = Application.OpenForms.Count - 1; index >= 0; index--) { if (Application.OpenForms[1].Name == "FormB") { Application.OpenForms[1].Close; } } Form formb = Application.OpenForms["FormB"]; form2.Close(); //Erro: A referência de objecto não foi definida como uma instância de um objecto. Edited February 23, 2014 at 08:45 PM by po1725
Solution nelsonr Posted February 23, 2014 at 10:05 PM Solution Report #546417 Posted February 23, 2014 at 10:05 PM Podes tentar assim: foreach(Form frm in Application.OpenForms) { if (frm is FormB) { frm.Close(); break; } } 1 Report
Amerco Ricky Posted May 10, 2018 at 06:44 AM Report #610500 Posted May 10, 2018 at 06:44 AM Em 23/02/2014 às 22:05, nelsonr disse: Podes tentar assim: foreach(Form frm in Application.OpenForms) { if (frm is FormB) { frm.Close(); break; } } Muito Obrigado Pelo Codigo..... Funcionou Muito Bem.... acredita so me Cadastrei para o felecitar...... MUITO Obeigado mesmo....
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now