How can I get the Xwinnerform to stay on top an keep the main form from bei开发者_开发百科ng clicked, I tried ShowDialog but I cant get it to work.
static public bool CheckWinner(Button[] myControls)
{
//bolean statement to check for the winner
bool gameOver = false;
for (int i = 0; i < 8; i++)
{
int a = Winners[i, 0];
int b = Winners[i, 1];
int c = Winners[i, 2];
Button b1 = myControls[a], b2 = myControls[b], b3 = myControls[c];
if (b1.Text == "" || b2.Text == "" || b3.Text == "")
continue;
if (b1.Text == b2.Text && b2.Text == b3.Text)
{
xWinnerForm xWinnerForm = new xWinnerForm();
xWinnerForm.ShowDialog(b1.Text + " is the Winner");
}
}
return gameOver;
}
enter code here
There is no overload of ShowDialog
that accepts a string. As was suggested to you in another question, do not use the Show
(or ShowDialog
) method to populate the value of a label. Either create a property on your form that gets and sets the text of the label or create a function that sets it, then just call ShowDialog(this)
.
Sounds like you need a MessageBox
MessageBox.Show(b1.Text + " is the Winner");
My guess is that you need to pass the parent form as an argument to ShowDialog
:
xWinnerForm.ShowDialog(mainForm);
Since you are passing it a string
, I'm guessing that you overloaded ShowDialog
in xWinnerForm
. Add an overload that also accepts the IWin32Window
parameter and passes it on to the base class method. Or better yet, do not overload ShowDialog
, but pass the window text to the xWinnerForm()
constructor instead.
精彩评论