Jump to content
  • Advertisement
Sign in to follow this  
Spa8nky

[XNA] How can I get WinForms to interact with the Game class?

This topic is 2755 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have an XNA window displaying inside a WinForm using the following:



[STAThread]
static void Main(string[] args)
{
// [Windows Forms]
MainForm form = new MainForm();
form.Show();

// [XNA Game]
Game1 game = new Game1(form.GetDrawSurface());
game.Run();
}


public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}

public IntPtr GetDrawSurface()
{
return pctSurface.Handle;
}

private void button1_Click(object sender, EventArgs e)
{
// Can't access Game1 from here
}
}


How can I now get the button1_Click method to control a parameter found in the Game1 class? Do I have to pass the Game1 class to the form during the Main method or is there a more appropriate method?

EDIT:

This is how I'm currently doing it:



[STAThread]
static void Main(string[] args)
{
// [Windows Forms]
MainForm form = new MainForm();
form.Show();

// [XNA Game]
Game1 game = new Game1(form.GetDrawSurface());
form.AssignGame(game);
game.Run();
}


public void AssignGame(Game1 game)
{
this.game = game;
}


Please shout if wrong :)

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!