显示对话问题

时间:2010-05-24 16:49:35

标签: c#

如何让Xwinnerform保持最佳状态以防止主要表单被点击,我尝试了ShowDialog,但我无法让它工作。

 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

3 个答案:

答案 0 :(得分:1)

ShowDialog没有接受字符串的重载。正如在另一个问题中向您建议的那样,请勿使用Show(或ShowDialog)方法填充标签的值。在表单上创建一个属性来获取和设置标签的文本,或创建一个设置它的函数,然后只需调用ShowDialog(this)

答案 1 :(得分:1)

听起来你需要MessageBox

MessageBox.Show(b1.Text + " is the Winner");

答案 2 :(得分:0)

我的猜测是你需要将父表单作为参数传递给ShowDialog

xWinnerForm.ShowDialog(mainForm);

由于您传递的是string,我猜您在ShowDialog中重载了xWinnerForm。添加一个也接受IWin32Window参数的重载并将其传递给基类方法。或者更好的是,不要重载ShowDialog,而是将窗口文本传递给xWinnerForm()构造函数。