C# 显示对话问题
我如何才能让XWinPerform保持在顶部并防止主窗体被单击,我尝试了ShowDialog,但无法使其工作C# 显示对话问题,c#,C#,我如何才能让XWinPerform保持在顶部并防止主窗体被单击,我尝试了ShowDialog,但无法使其工作 static public bool CheckWinner(Button[] myControls) { //bolean statement to check for the winner bool gameOver = false; for (int i =
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
static public bool CheckWinner(按钮[]myControls)
{
//bolean声明检查是否有获胜者
bool gameOver=false;
对于(int i=0;i<8;i++)
{
int a=优胜者[i,0];
int b=优胜者[i,1];
int c=优胜者[i,2];
按钮b1=myControls[a],b2=myControls[b],b3=myControls[c];
如果(b1.Text==“”| | b2.Text==“”| | b3.Text==“”)
继续;
if(b1.Text==b2.Text&&b2.Text==b3.Text)
{
xwinnexperform xwinnexperform=新的xwinnexperform();
xWinPerform.ShowDialog(b1.Text+“是赢家”);
}
}
返回游戏结束;
}
在这里输入代码
我猜您需要将父窗体作为参数传递给:
由于您正在向它传递一个
字符串
,我猜您在xwinneform
中重载了ShowDialog
。添加一个重载,该重载也接受IWin32Window
参数,并将其传递给基类方法。或者更好的方法是,不要重载ShowDialog
,而是将窗口文本传递给xWinPerform()
构造函数。没有重载接受字符串的ShowDialog
。正如在另一个问题中向您建议的那样,不要使用Show
(或ShowDialog
)方法填充标签的值。在表单上创建一个属性来获取和设置标签文本,或者创建一个函数来设置标签文本,然后只需调用ShowDialog(this)
听起来您需要一个消息框
MessageBox.Show(b1.Text + " is the Winner");
“…无法让它工作”太含糊了。什么不起作用?你能解释一下“不能让它起作用”吗ShowDialog是合适的方法。它说与“name”匹配的最佳重载方法有一些无效的参数。您的评论表明Thomas的答案是正确的。我是新手,如果不太麻烦,您能给我一个更清楚的例子吗?我在其中有一个,但项目需要通过类调用from
MessageBox.Show(b1.Text + " is the Winner");