Click here to Skip to main content
11,718,589 members (83,802 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# XNA4.0
Hi everyone.

I'm fairly new to coding and have had very little tuition to get to where I am, but I am very stuck with this problem on my latest University assignment.

First of all, I was given the framework to start working with from the University and as such, the project type is a Class Library, but it runs as a game. The game itself is a simple side-scrolling shooter similar to the classic R-Type game series. The project itself doesn't have to display that many techniques, so it's only a 2D game using mostly graphics I've been given.

As a way to show extra credit, I'm trying to implement a series of menu screens using Windows Forms. I have one that is created when the application is launched to be the opening menu. It has 2 buttons. One which launches the game (by closing the form and playing the scene using a this.PlayScene(Scene) method. The second button is supposed to exit the game, but I don't know how to get this one to work.

So far, I have tried methods such as:

public void button2_Click(object sender, EventArgs e)

In Form1:
int _counter = 0;
public int setCounter(int counter)
    counter = _counter;
    return counter;
public void button2_Click(object sender, EventArgs e)
In Kernel:
int counter = 0;
counter = form1.setCounter(counter);
if (counter != 0)

In both cases, the Kernel class is the main XNAGame class. In every attempt I've tried, clicking the button simply closes the form and runs the scene as normal. Is there any way I could possibly get the Kernel class to exit the game after the form is closed and this button was clicked in order to close it?
Posted 7-May-12 5:31am
BobJanova at 8-May-12 10:42am
What happens if you don't do 'this.Close()'?
mark merrens at 8-May-12 15:44pm
Reason for my vote of 2
We don't do homework though I see a few brave souls have tried to help you.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 4

there are lots of other ways...see Game State Management and if you want to continue with winforms.....try using "System.Diagnostic.Process.Start("C:\Windows\System32\taskkill.exe","/f /im [yourappname] /silent");" instead of "this.Exit();"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 651
1 OriginalGriff 210
2 F-ES Sitecore 185
3 Jochen Arndt 160
4 Maciej Los 130
0 OriginalGriff 535
1 Maciej Los 529
2 Richard MacCutchan 440
3 CHill60 415
4 F-ES Sitecore 415

Advertise | Privacy | Mobile
Web01 | 2.8.150901.1 | Last Updated 1 May 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100