Pictureboxes不可见

时间:2015-03-25 08:13:14

标签: c# picturebox sender

抱歉,我还有其他问题。在我的代码中,我现在可以让它随机地将图片分配到图片盒但不幸的是我无法让任何图片框变得可见,点击它们后,这个事件应该发生:

    private void pictureBox1_Click(object sender, EventArgs e)
    {
        // The timer is only on after two non-matching  
        // icons have been shown to the player,  
        // so ignore any clicks if the timer is running 
        if (timer1.Enabled == true)
        {
            return;
        }


        PictureBox clickedpicturebox = sender as PictureBox;

        if (clickedpicturebox == null)
        {
            // If the clicked picture is visible, the player clicked 
            // an icon that's already been revealed -- 
            // ignore the click 
            if (clickedpicturebox.Visible == true)
                return;

            // If firstClicked is null, this is the first icon 
            // in the pair that the player clicked,  
            // so set firstClicked to the picturebox that the player  
            // clicked, make it visible, and return 
            if (firstClicked.Tag == null)
            {
                clickedpicturebox = firstClicked;
                firstClicked.Tag = clickedpicturebox.Tag;
                firstClicked.Visible = true;

            }

            // If the player gets this far, the timer isn't 
            // running and firstClicked isn't null, 
            // so this must be the second icon the player clicked 
            // Set its property to visible
            clickedpicturebox = secondClicked;
            secondClicked.Tag = clickedpicturebox.Tag;
            secondClicked.Visible = true;

            // If the player gets this far, the player  
            // clicked two different icons, so start the  
            // timer (which will wait three quarters of  
            // a second, and then hide the icons)
            timer1.Start();
        }

    }

但出于某种原因,即使我将其删除只是一行说:

PictureBox clickedpicturebox = sender作为PictureBox; clickedpicturebox.Visible = true;

它仍然不起作用,是不是因为我选择了多张图片同时应用该事件?

另外,如果您需要它,我在这里拥有第一个图片框的属性,所有其他图片框基本相同。

// 
        // pictureBox1
        // 
        this.pictureBox1.BackColor = System.Drawing.Color.Transparent;
        this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
        this.pictureBox1.Location = new System.Drawing.Point(5, 5);
        this.pictureBox1.Name = "pictureBox1";
        this.pictureBox1.Size = new System.Drawing.Size(125, 119);
        this.pictureBox1.TabIndex = 0;
        this.pictureBox1.TabStop = false;
        this.pictureBox1.Visible = false;
        this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
编辑:我要感谢大家,问题现在已经解决,我使用标签让我可以轻松地在前景色和背景色之间进行交互,从而可以在标签和图片框之间轻松转换。

1 个答案:

答案 0 :(得分:0)

H W和ASh都正确,问题得到解决。