satbr 1 Posted February 25, 2019 Report Share Posted February 25, 2019 Boa tarde, Estava aqui a testar uma situação em que na form principal (Form1) ao iniciar abre também a Form3 e ao clicar num botão abre a Form2 e fecha a Form3. Mas não estou a conseguir a Form3 continua sempre aberta, não fecha ao clicar no botão. Eis o me código: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace TESTE2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); Form test = new Form3(); test.Show(); } private Form3 form3; private void button1_Click(object sender, EventArgs e) { form3.Close(); Form test2 = new Form2(); test2.Show(); } } } Link to post Share on other sites
Gnrtuga 21 Posted February 25, 2019 Report Share Posted February 25, 2019 Boas, visto assim no telefone, parece-me que o erro é que estás a criar : Form test = new Form3(); e depois mandas fechar o form3.Close(); ou seja não estás a mandar fechar o que criastes. boa sorte. Férias! Estou por aqui: http://maps.google.p...001549&t=h&z=20 (a bulir claro está!) Nunca mais é verão outra vez.. Link to post Share on other sites
satbr 1 Posted February 25, 2019 Author Report Share Posted February 25, 2019 11 minutos atrás, Gnrtuga disse: Boas, visto assim no telefone, parece-me que o erro é que estás a criar : Form test = new Form3(); e depois mandas fechar o form3.Close(); ou seja não estás a mandar fechar o que criastes. boa sorte. Mas se meter assim dá erro: private void button1_Click(object sender, EventArgs e) { test.close(); Form test2 = new Form2(); test2.Show(); } Link to post Share on other sites
Mikev 1 Posted February 25, 2019 Report Share Posted February 25, 2019 (edited) 21 minutos atrás, satbr disse: Mas se meter assim dá erro: private void button1_Click(object sender, EventArgs e) { test.close(); Form test2 = new Form2(); test2.Show(); } Dá te erro porque estás a fechar primeiro e só depois abrir o novo form, ou seja não irá realmente abrir. Tenta assim: Form test2 = new Form2(); test2.Show(); test.Close(); //ou entao "this.Close()" Edited February 25, 2019 by Mikev C# 😍 Link to post Share on other sites
satbr 1 Posted February 25, 2019 Author Report Share Posted February 25, 2019 5 minutos atrás, Mikev disse: Dá te erro porque estás a fechar primeiro e só depois abrir o novo form, ou seja não irá realmente abrir. Tenta assim: Form test2 = new Form2(); test2.Show(); test.Close(); //ou entao "this.Close()" se fizer "this.Close();" fecha a form1 e a form3 continua aberta Link to post Share on other sites
Mikev 1 Posted February 25, 2019 Report Share Posted February 25, 2019 (edited) 1 hora atrás, satbr disse: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace TESTE2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); Form test = new Form3(); test.Show(); } private void button1_Click(object sender, EventArgs e) { test.Close(); Form test2 = new Form2(); test2.Show(); } } } Tinha percebido mal quanto ao problema, li outra vez o que escreveste e fiz umas alterações no teu código inicial. Com isso vai ao abrir o projeto irá ter 2 forms ( o form 1 e o form 3). Ao clicares no button1 vai te fechar o form 3 e vai abrir um novo form o 2. Coloca assim o código exatamente, e se te der algum erro, mostra-nos para te ajudarmos. Edited February 25, 2019 by Mikev C# 😍 Link to post Share on other sites
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