PictureBox悬停在参数无效问题上

问题描述 投票:0回答:1

我有3个图片框,其中包含来自列表字符串的图像。有一个按钮会遍历列表字符串中的每个元素,依次更新3个图片框,其中包含3个图像的图片框为picturebox3、4和5。在图像上展开以将图像扩展到另一个图片框,该图片框将一直隐藏,直到鼠标位于其上方为止。我创建了3个额外的图片框,分别是pictureBox6、7和8,以显示与picturebox3、4和5有关的放大图像。picturebox6与3有关,picturebox 7与4有关,而8与5有关。我尝试将鼠标悬停在图片上之后,将图片框设置为null,但这没有用。下面是图片框3、4和5中要在列表中进行更新的代码,其中还包括事件触发器。

download_file_names [] =文件名“ .jpg”matching_image_for_Processing [intIndex] =存放文件的文件夹

这些变量在我浏览列表时确实发生了变化,所以我知道这是可行的

[在鼠标离开图像后,我试图将picturebox设置为null,但是仍然没有效果。

下面是图片框3、4和5中要更新的图像的代码,它还包含事件触发器。

if (download_file_names.ElementAtOrDefault(0) != null)
               {
                   pictureBox3.Image = new Bitmap(Environment.CurrentDirectory + "\\" + "temp_data" + "\\" + matching_image_for_Processing[intIndex] + "\\" + download_file_names[0]);
                   pictureBox3.MouseHover += new EventHandler((sender2, e2) => pictureBox3_Mouse(sender2, e2, download_file_names[0], matching_image_for_Processing[intIndex]));
                   pictureBox3.MouseLeave += new EventHandler(pictureBox3_MouseLeave);
               }
               else
               {
                   pictureBox3.Image = new Bitmap(Environment.CurrentDirectory + "\\" + "NoImage.bmp");

               }

               if (download_file_names.ElementAtOrDefault(1) != null)
               {
                   pictureBox4.Image = new Bitmap(Environment.CurrentDirectory + "\\" + "temp_data" + "\\" + matching_image_for_Processing[intIndex] + "\\" + download_file_names[1]);
                   pictureBox4.MouseHover += new EventHandler((sender2, e2) => pictureBox4_Mouse(sender2, e2, download_file_names[1], matching_image_for_Processing[intIndex]));
                   pictureBox4.MouseLeave += new EventHandler(pictureBox4_MouseLeave);
               }
               else
               {
                   pictureBox4.Image = new Bitmap(Environment.CurrentDirectory + "\\" + "NoImage.bmp");
               }

               if (download_file_names.ElementAtOrDefault(2) != null)
               {
                   pictureBox5.Image = new Bitmap(Environment.CurrentDirectory + "\\" + "temp_data" + "\\" + matching_image_for_Processing[intIndex] + "\\" + download_file_names[2]);
                   pictureBox5.MouseHover += new EventHandler((sender2, e2) => pictureBox5_Mouse(sender2, e2, download_file_names[2], matching_image_for_Processing[intIndex]));
                   pictureBox5.MouseLeave += new EventHandler(pictureBox5_MouseLeave);

               }
               else
               {
                   pictureBox5.Image = new Bitmap(Environment.CurrentDirectory + "\\" + "NoImage.bmp");
               }

下面是其他图片框显示较大图像的代码。

void pictureBox3_Mouse(object sender, EventArgs e, string catching, string catching2)
       {

           pictureBox6.Visible = true;
           pictureBox6.Image = new Bitmap(Environment.CurrentDirectory + "\\" + "temp_data" + "\\" + catching2 + "\\" + catching);
           Console.WriteLine("temp_data" + "\\" + catching2 + "\\" + catching);
           pictureBox6.Refresh();




       }

       void pictureBox3_MouseLeave(object sender, EventArgs e)
       {
           pictureBox6.Visible = false;
           pictureBox6.Image = null;
           pictureBox6.Refresh();

       }

       void pictureBox4_Mouse(object sender, EventArgs e, string catching_1, string catching2_1)
       {


                pictureBox7.Visible = true;
               pictureBox7.Image = new Bitmap(Environment.CurrentDirectory + "\\" + "temp_data" + "\\" + catching2_1 + "\\" + catching_1);
               pictureBox7.Refresh();


       }

       void pictureBox4_MouseLeave(object sender, EventArgs e)
       {
           pictureBox7.Visible = false;
           pictureBox7.Image = null;
           pictureBox7.Refresh();

       }

       void pictureBox5_Mouse(object sender, EventArgs e, string catching_2, string catching2_2)
       {


              pictureBox8.Visible = true;
               pictureBox8.Image = new Bitmap(Environment.CurrentDirectory + "\\" + "temp_data" + "\\" + catching2_2 + "\\" + catching_2);
               pictureBox8.Refresh();


       }

       void pictureBox5_MouseLeave(object sender, EventArgs e)
       {
           pictureBox8.Visible = false;
           pictureBox8.Image = null;
           pictureBox8.Refresh();

       }

我希望有人可以帮助我解决这个问题,因为我转到列表中的下一个元素并将鼠标悬停在新图像上,所以我不断收到错误参数无效。我相信picturebox保留了以前的变量。]​​>

我有3个图片框,其中包含来自列表字符串的图像。有一个按钮会遍历列表字符串中的每个元素,依次更新3个图片框,这些图片框会......>

c# mouseevent picturebox
1个回答
0
投票

没有必要将“可见”图片框设置为false。

// pictureBox1 image
// pictureBox2 enlarged image
Image image;
private void Form1_Load(object sender, EventArgs e)
{
    pictureBox1.Image = Image.FromFile(@"D:\pic\a.jpg");
    image = pictureBox1.Image;
}

private void pictureBox1_MouseHover(object sender, EventArgs e)
{
    pictureBox1.Image = null;
    pictureBox2.Image = image;
}

private void pictureBox1_MouseLeave(object sender, EventArgs e)
{
    pictureBox1.Image = image;
    pictureBox2.Image = null;
}
© www.soinside.com 2019 - 2024. All rights reserved.