-1

I am trying to make a winform open an Xna form. looking online the best way I discovered was to open the form first through program.cs, and then put an if statement that checks if you hit the start button on the winform that will give DialogResult.OK . I know I need to start the form using ShowDialog, but I get two forms with my current code. it opens one, I close it, it opens another winform and when you close that, you get the Xna form. Any suggestions? here is my code:

     static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    static void Main(string[] args)
    {
      using(Form1 form = new Form1())
      {
          form.ShowDialog();
          if(form.ShowDialog() == DialogResult.OK)
          {
              using (Game1 game = new Game1())
              {
                  game.Run();
              }

          }

          }
      }
    }

here is my button code:

           private void button1_Click(object sender, EventArgs e)
    {
        compotents comps = new compotents();
      comps.mass =   textBox1.Text;
      comps.velocity = textBox2.Text;
      comps.gravity = textBox3.Text;

      button1.DialogResult = DialogResult.OK;

      this.Close();
    }

(compotents is a class i am using to store variables and use them in the xna form)

Alexandre
  • 148
  • 7

1 Answers1

0

The form shows twice because you are calling ShowDialog twice but not doing anything with the first call's result. Change to:

  using(Form1 form = new Form1())
  {
      if(form.ShowDialog() == DialogResult.OK)
      {
          using (Game1 game = new Game1())
          {
              game.Run();
          }
      }
  }
D Stanley
  • 149,601
  • 11
  • 178
  • 240
  • I ran it without the first form.ShowDialog, but it the entire thing closes after i hit the start button without it... – Alexandre Jul 21 '15 at 17:12
  • Does `game.Run` spawn threads or something? Have you tried running it in the debugger to see if the problem becomes apparent? – D Stanley Jul 21 '15 at 17:20
  • when i run it in the debugger, no problem seems apparent in it. No flags pop up, or Exceptions, I press the button and the entire debugger closes as if i closed the application. The game.Run is only supposed to open an Xna form. I am new to Xna though, so it may be that game.Run only calls the code to start. I am not sure. I don't see what the problem would be if it works when i call ShowDialog twice. – Alexandre Jul 21 '15 at 17:31