【问题标题】:Pictureboxes not becoming visible图片框不可见
【发布时间】:2015-03-25 08:13:14
【问题描述】:

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

    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 = 作为 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);

编辑:谢谢大家,现在问题已经解决了,我已经使用了标签让我可以轻松地在前景色和背景色之间进行交互,从而可以轻松地在标签和图片框之间进行转换。

【问题讨论】:

  • 你能提供一个完整的可验证的可运行示例吗? P.S.:别找借口,我不认识你。
  • pictureBox1_Click 会运行吗? pictureBox1.Visible = false;我觉得不能点击
  • @BinkanSalaryman,它只是空白,如果此代码到位,则实际上没有什么可看或做的,这就是为什么我如此困惑,没有它,如果我设置它们,所有图片都在那里要启用的可见属性。
  • 那么,如果我想看不到图片并仍然点击它,我应该在@ASh 中添加什么属性?我应该玩弄颜色吗?
  • 基本上用户只能与他能看到的东西进行交互。您仍然可以单击底层表单(或显示的任何控件而不是图片框)并将单击位置与图像的边界/位置进行比较。然后,如果位置匹配,您可以从 Form1_Click 事件中触发 pictureBox1_Click

标签: c# picturebox sender


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-24
    • 2019-10-31
    • 2023-03-20
    • 2021-02-15
    • 1970-01-01
    相关资源
    最近更新 更多