Alaa M.
Alaa M.

Reputation: 5273

error on exiting a window

In the following picture, when i click File->New Game I see this window: enter image description here

If i continue and press Start Game, everything works great. But if i just click the red X, i get this error: enter image description here

This is the code for File->New Game:

private: System::Void newGameToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e)
    {
        NG->ShowDialog();
        ShowPossible();
        update_score();
        if(pc_exists()==1)
            ComputerPlay();
    }

NG->ShowDialog() shows the New Game dialog.

And then ShowPossible() shows something on the board (hints for possible moves). And that's what's making trouble. I need some code that quits from newGameToolStripMenuItem_Click() on X click instead of continuing to ShowPossible().

I tried making a global variable called ready in form NewGame, and at form load initialized it with 0, and only when i click Start Game it turns to 1. And finally added this condition in the above function:

...
if(ready)
    ShowPossible();
...

So this way if i don't click Start Game, and only click X, ready will be 0 and it won't enter ShowPossible(). But it didn't work. Somehow when the code for the button Start Game finishes, ready is still 0.

Is there any more efficient way to deal with this?

Thank you !

Upvotes: 0

Views: 53

Answers (1)

ryrich
ryrich

Reputation: 2204

EDITED:

Since you are using System.Windows.Forms, check against the DialogResult enumeration (Thanks chris):

if (NG->ShowDialog() == System::Windows::Forms::DialogResult::Cancel)
    return;

From MSDN:

When a form is displayed as a modal dialog box, clicking the Close button (the button with an X at the upper-right corner of the form) causes the form to be hidden and the DialogResult property to be set to DialogResult.Cancel.

Upvotes: 1

Related Questions