Click here to Skip to main content
15,077,641 members
Please Sign up or sign in to vote.
4.55/5 (4 votes)
See more:
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?
BobJanova 8-May-12 10:42am
What happens if you don't do 'this.Close()'?
R. Giskard Reventlov 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

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)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900