2016-12-14 1 views
0

Quelqu'un peut-il expliquer pourquoi mon nouveau formulaire n'apparaît pas? L'ancienne forme ferme mais il n'a pas été remplacée par mon nouveau:Le nouveau formulaire n'apparaît pas

namespace Pong 
{ 
    public partial class Menu : Form 
    { 
     public Menu() 
     { 
      InitializeComponent(); 
     } 

     private void pictureBox1_Click(object sender, EventArgs e) 
     { 

     } 

     private void PlayButton_Click(object sender, EventArgs e) 
     { 
      PongForm form = new PongForm(); 
      form.Show(); 
      this.Close(); 
     } 

     private void ExitButton_Click(object sender, EventArgs e) 
     { 
      this.Close(); 
     } 
    } 
} 

Répondre

1

est « Menu » le démarrage formulaire pour votre application? Si oui, alors quand il se ferme l'ensemble de l'application se ferme.

Une solution serait de cacher la forme actuelle, affichage "forme" avec ShowDialog(), puis appelez Fermer():

private void PlayButton_Click(object sender, EventArgs e) 
    { 
     this.Visible = false; // hide the current form 
     Application.DoEvents(); 

     PongForm form = new PongForm(); 
     form.ShowDialog(); // code stops here until PongForm is dismissed 

     this.Close(); // now close the form (and presumable the whole app) 
    }