Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如果PictureBox单击事件_C# - Fatal编程技术网

C# 如果PictureBox单击事件

C# 如果PictureBox单击事件,c#,C#,我正试着编一个匹配的游戏。我的想法是: (1) 。单击某个pictureBox1时,它将不可见 (2) 。此时会出现一个消息框,提示“选择另一个框” (3) 。最后,我需要编写一个if/else语句,如果单击了pictureBox13,它将不可见else,(如果单击了另一个pictureBox)一个MessageBox提示“重试”。两个图片框都不可见,但我不知道我做错了什么: // Program From Below private void pictureBox1_Click

我正试着编一个匹配的游戏。我的想法是:

(1) 。单击某个
pictureBox1
时,它将不可见

(2) 。此时会出现一个
消息框
,提示“选择另一个框”

(3) 。最后,我需要编写一个
if/else
语句,如果单击了
pictureBox13
,它将不可见
else
,(如果单击了另一个
pictureBox
)一个
MessageBox
提示“重试”。两个图片框都不可见,但我不知道我做错了什么:

    // Program From Below
    private void pictureBox1_Click(object sender, EventArgs e)
    {
        MessageBox.Show("Now Pick Another Hidden Picture!");
        pictureBox1.Visible = false;

        if (pictureBox13_Click)
        {
            MessageBox.Show("Great!");
            pictureBox13.Visible = false;
        }
        else
        {
            MessageBox.Show("Try Again!");
        }


    }

if(pictureBox13\u Click)

下面有一条红色的曲线,如果每个PictureBox都有一个状态,那么最好使用Click\u事件来操纵它。微软在这里有一个关于匹配游戏的全面教程:

如果每个PictureBox都有一个状态,那就更好了,你可以使用点击事件来操纵它。微软在这里有一个关于匹配游戏的全面教程:

如果每个PictureBox都有一个状态,那就更好了,你可以使用点击事件来操纵它。微软在这里有一个关于匹配游戏的全面教程:

如果每个PictureBox都有一个状态,那就更好了,你可以使用点击事件来操纵它。Microsoft在此处提供了一个匹配游戏的全面教程:

您可以为同时设置为0的选定框(在本例中为box1和box2)创建一个
int
,然后创建一个单击事件,将int设置为单击框

if(box1 != 0) 
    {
        box2 = 'insert selected box number'
    }
    else
    {
        box1 = 'insert selected box number'
    }

选择两个框后,两个
整数
都可以设置为false,这允许您使用
开关
,而不是
if
,如果每对图片都需要一个单独的
if
语句,则可以大大缩短代码。

您可以为同时设置为0的选定框(在本例中为box1和box2)创建一个
int
,然后创建一个单击事件,将int设置为单击框

if(box1 != 0) 
    {
        box2 = 'insert selected box number'
    }
    else
    {
        box1 = 'insert selected box number'
    }

选择两个框后,两个
整数
都可以设置为false,这允许您使用
开关
,而不是
if
,如果每对图片都需要一个单独的
if
语句,则可以大大缩短代码。

您可以为同时设置为0的选定框(在本例中为box1和box2)创建一个
int
,然后创建一个单击事件,将int设置为单击框

if(box1 != 0) 
    {
        box2 = 'insert selected box number'
    }
    else
    {
        box1 = 'insert selected box number'
    }

选择两个框后,两个
整数
都可以设置为false,这允许您使用
开关
,而不是
if
,如果每对图片都需要一个单独的
if
语句,则可以大大缩短代码。

您可以为同时设置为0的选定框(在本例中为box1和box2)创建一个
int
,然后创建一个单击事件,将int设置为单击框

if(box1 != 0) 
    {
        box2 = 'insert selected box number'
    }
    else
    {
        box1 = 'insert selected box number'
    }

选择两个框后,两个
整数都可以设置为false,这允许您使用
开关而不是
if
,如果每对图片都需要单独的
if
语句,这将大大缩短代码。

如其他建议,您可以对所有PictureBox使用相同的事件处理程序,并将
sender
转换为
PictureBox
以查看单击了什么PB:

List<string> selectedPictureBoxes;

public MyForm()  // ctor
{
   selectedPictureBoxes = new List<string>();

   foreach(Control c in this.Controls) 
      if(c is PictureBox) c.Click += pictureBox_Click;
}

private void pictureBox_Click(object sender, EventArgs e)
{
    PictureBox _clicked = sender as PictureBox;

    if(!selectedPictureBoxes.Contains(_clicked.Name))
       selectedPictureBoxes.Add(_clicked.Name);
    else ....
}
列出所选图片框;
公共MyForm()//
{
selectedPictureBoxes=新列表();
foreach(此.Controls中的控件c)
如果(c是PictureBox)c.单击+=PictureBox\u单击;
}
私有无效pictureBox\u单击(对象发送方,事件参数e)
{
PictureBox _clicked=发送者作为PictureBox;
如果(!selectedPictureBoxes.Contains(_clicked.Name))
选择PictureBoxes.Add(\单击.Name);
其他的
}

如其他建议,您可以对所有PictureBox使用相同的事件处理程序,并将
发送方
转换为
PictureBox
以查看单击了什么PB:

List<string> selectedPictureBoxes;

public MyForm()  // ctor
{
   selectedPictureBoxes = new List<string>();

   foreach(Control c in this.Controls) 
      if(c is PictureBox) c.Click += pictureBox_Click;
}

private void pictureBox_Click(object sender, EventArgs e)
{
    PictureBox _clicked = sender as PictureBox;

    if(!selectedPictureBoxes.Contains(_clicked.Name))
       selectedPictureBoxes.Add(_clicked.Name);
    else ....
}
列出所选图片框;
公共MyForm()//
{
selectedPictureBoxes=新列表();
foreach(此.Controls中的控件c)
如果(c是PictureBox)c.单击+=PictureBox\u单击;
}
私有无效pictureBox\u单击(对象发送方,事件参数e)
{
PictureBox _clicked=发送者作为PictureBox;
如果(!selectedPictureBoxes.Contains(_clicked.Name))
选择PictureBoxes.Add(\单击.Name);
其他的
}

如其他建议,您可以对所有PictureBox使用相同的事件处理程序,并将
发送方
转换为
PictureBox
以查看单击了什么PB:

List<string> selectedPictureBoxes;

public MyForm()  // ctor
{
   selectedPictureBoxes = new List<string>();

   foreach(Control c in this.Controls) 
      if(c is PictureBox) c.Click += pictureBox_Click;
}

private void pictureBox_Click(object sender, EventArgs e)
{
    PictureBox _clicked = sender as PictureBox;

    if(!selectedPictureBoxes.Contains(_clicked.Name))
       selectedPictureBoxes.Add(_clicked.Name);
    else ....
}
列出所选图片框;
公共MyForm()//
{
selectedPictureBoxes=新列表();
foreach(此.Controls中的控件c)
如果(c是PictureBox)c.单击+=PictureBox\u单击;
}
私有无效pictureBox\u单击(对象发送方,事件参数e)
{
PictureBox _clicked=发送者作为PictureBox;
如果(!selectedPictureBoxes.Contains(_clicked.Name))
选择PictureBoxes.Add(\单击.Name);
其他的
}

如其他建议,您可以对所有PictureBox使用相同的事件处理程序,并将
发送方
转换为
PictureBox
以查看单击了什么PB:

List<string> selectedPictureBoxes;

public MyForm()  // ctor
{
   selectedPictureBoxes = new List<string>();

   foreach(Control c in this.Controls) 
      if(c is PictureBox) c.Click += pictureBox_Click;
}

private void pictureBox_Click(object sender, EventArgs e)
{
    PictureBox _clicked = sender as PictureBox;

    if(!selectedPictureBoxes.Contains(_clicked.Name))
       selectedPictureBoxes.Add(_clicked.Name);
    else ....
}
列出所选图片框;
公共MyForm()//
{
selectedPictureBoxes=新列表();
foreach(此.Controls中的控件c)
如果(c是PictureBox)c.单击+=PictureBox\u单击;
}
私有无效pictureBox\u单击(对象发送方,事件参数e)
{
PictureBox _clicked=发送者作为PictureBox;
如果(!selectedPictureBoxes.Contains(_clicked.Name))
选择PictureBoxes.Add(\单击.Name);
其他的
}

如果(点击图片box13)
?!它可能是一个方法的名称,而不是布尔变量。只需在单击时使每个
PictureBox
不可见即可。每个PictureBox都需要自己的单击事件代码,或者创建一个通用的单击方法,使所有PictureBox都可以