鼠标单击后显示图片框的内容

时间:2018-12-20 01:48:16

标签: c# winforms picturebox

单击后,我试图在pictureBox中显示图像。

首先,我尝试将PictureBox属性的可见性设置为false,然后单击PictureBox,使这些选项变为现实,并应显示图片。 这是行不通的。 请告诉我此操作的最佳实践是什么。

这是我的PictureBox列表

List<PictureBox> logos = new List<PictureBox>();
//Here how I put Images into every single PictureBox:

 private void f1()
    {
        Insert_Logo();
        PictureBox picture;
        int randomnumber;

        for(int i=0; i< tableLayoutPanel1.Controls.Count; i++)
        {
            if (tableLayoutPanel1.Controls[i] is PictureBox)
            {                      
                    picture = (PictureBox)tableLayoutPanel1.Controls[i];
            }
            else
                continue;

            randomnumber = random.Next(0, logos.Count);
            picture.Image = logos[randomnumber].Image;             
            logos.RemoveAt(randomnumber);                
        }

    }

这是我单击PictureBox后试图显示图像的功能:

    private void PictuteBox_CLICK(object sender, EventArgs e)
    {

        PictureBox clickedPicture = sender as PictureBox;

        if(clickedPicture == null)
        {
            return;
        }

        if (firsPic == null)
        {
            firsPic = clickedPicture;
            firsPic.Visible = true;
            return;
        }

    }    

这是在PictureBox中插入图片的代码:

       private List<PictureBox> Insert_Logo()
    {
        PictureBox pic1 = new PictureBox();
        Image image = Image.FromFile("D:\\Project\\Mini-Game\\Mini-Game\\bin\\Image\\Renault.bmp");
        pic1.Image = image;

        PictureBox pic2 = new PictureBox();
        Image a = Image.FromFile("D:\\Project\\Mini-Game\\Mini-Game\\bin\\Image\\vw.bmp");
        pic2.Size = new Size(a.Width, a.Height);
        pic2.Image = a;

        PictureBox pic3 = new PictureBox();
        Image s = Image.FromFile("D:\\Project\\Mini-Game\\Mini-Game\\bin\\Image\\alfa.bmp");
        pic3.Size = new Size(s.Width, s.Height);
        pic3.Image = s;

        logos.Add(pic1);
        logos.Add(pic2);
        logos.Add(pic3);
        logos.Add(pic4);
        logos.Add(pic5);
        logos.Add(pic6);

return logos;

1 个答案:

答案 0 :(得分:1)

我认为您应该这样编写代码,并附上注释

django.core.paginator