C# I';我试图在pictureBox中显示当前图像并拉伸它,但它';他什么也没表现出来为什么?

C# I';我试图在pictureBox中显示当前图像并拉伸它,但它';他什么也没表现出来为什么?,c#,winforms,C#,Winforms,在For1中,我有以下代码: private void timer1_Tick(object sender, EventArgs e) { try { this.pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox1.Load(file_array_satellite[file_i

在For1中,我有以下代码:

private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {     
                this.pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                pictureBox1.Load(file_array_satellite[file_indxs_satellite]);
                file_indxs_satellite = file_indxs_satellite - 1;
                if (file_indxs_satellite < 0)
                {
                    file_indxs_satellite = file_array_satellite.Length - 1;
                }
            }
            catch
            {
                timer1.Enabled = false;
            }
        }

        private void satellitesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            file_array_satellite = Directory.GetFiles(UrlsPath, "RainImage*.*");
            if (file_array_satellite.Length > 0)
            {
                DateTime[] creationTimes8 = new DateTime[file_array_satellite.Length];
                for (int i = 0; i < file_array_satellite.Length; i++)
                    creationTimes8[i] = new FileInfo(file_array_satellite[i]).CreationTime;
                Array.Sort(creationTimes8, file_array_satellite);
                file_indxs_satellite = 0;
                file_indxs_satellite = file_array_satellite.Length - 1;
                timer1.Enabled = true;
            }
        }

        private void pictureBox1_MouseEnter(object sender, EventArgs e)
        {
            this.pictureBox1.Size = new Size(500, 500);
            pictureBox1.Location = new Point(this.Bounds.Width / 2,
                            this.Bounds.Height / 2);
            this.pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            pictureBox1.BringToFront();
        }

        private void pictureBox1_MouseLeave(object sender, EventArgs e)
        {

                this.pictureBox1.Size = new Size(100, 100);
                pictureBox1.Location = new Point(12,
                                27);

        }
private void timer1\u勾选(对象发送方,事件参数e)
{
尝试
{     
this.pictureBox1.SizeMode=PictureBoxSizeMode.StretchImage;
pictureBox1.Load(文件数组卫星[文件索引卫星]);
file_indxs_satellite=file_indxs_satellite-1;
if(文件索引卫星<0)
{
file_indxs_satellite=file_array_satellite.Length-1;
}
}
抓住
{
timer1.Enabled=false;
}
}
私有void卫星工具条带菜单项单击(对象发送方,事件参数e)
{
file\u array\u satellite=Directory.GetFiles(UrlsPath,“RainImage**”);
如果(文件\u数组\u satellite.Length>0)
{
DateTime[]creationTimes8=新的日期时间[文件\数组\卫星.Length];
对于(int i=0;i
在原始版本中,picturebox1的大小为100x100,每个图像都经过拉伸以适合pictureBox。 当它为100x100时,一切正常,我在pictureBox中看到每个图像的动画

现在我做了一个事件,当我用鼠标进入pictureBox区域时,它应该移动到表单的中心,调整大小为500x500,拉伸图像并显示相同的动画。 当我离开pictureBox区域时,它应该恢复到原来的大小和位置

当我用鼠标进入pictureBox1区域时,pictureBox消失了,我在任何地方都看不到它,一旦我离开pictureBox区域,我看到它在原来的位置和大小为100x100

为什么当我用鼠标进入pictureBox1区域时,它消失了?我看不到它位于表单中心,尺寸为500x500

file_array_satellite为字符串[],file_indxs_satellite为int

RainImage**是下载后硬盘上的文件名


这个想法不是每次我进入或离开时都转换/更改硬盘上的文件大小,因此我希望一旦我进入pictureBox1区域,它将拉伸pictureBox中的当前图像并显示它。它在100x100时工作,但在500x500上不工作。

我可以大胆猜测,
this.Bounds.Width
this.Bounds.Height
并不是你所期望的,所以PictureBox不会消失,你只是将它设置到屏幕外/窗体外的某个位置。在调试模式下运行Visual Studio,并在该行周围放置一个断点,然后查看此.Bounds
等于什么。这可能会为您提供一个关于需要设置的正确位置的线索。

我可以大胆猜测
This.Bounds.Width
This.Bounds.Height
不是您期望的位置,因此PictureBox不会消失,您只是将其设置到屏幕外/窗体外的某个位置。在调试模式下运行Visual Studio,并在该行周围放置一个断点,然后查看此.Bounds等于什么。这可能会为您提供一个关于需要设置的正确位置的线索。

我可以大胆猜测
This.Bounds.Width
This.Bounds.Height
不是您期望的位置,因此PictureBox不会消失,您只是将其设置到屏幕外/窗体外的某个位置。在调试模式下运行Visual Studio,并在该行周围放置一个断点,然后查看此.Bounds等于什么。这可能会为您提供一个关于需要设置的正确位置的线索。

我可以大胆猜测
This.Bounds.Width
This.Bounds.Height
不是您期望的位置,因此PictureBox不会消失,您只是将其设置到屏幕外/窗体外的某个位置。在调试模式下运行Visual Studio,并在该行周围放置一个断点,然后查看此.Bounds等于什么。这可能会为您提供需要设置的正确位置的线索。

当您将鼠标悬停在PictureBox上并将其移动到表单的中心时,您正在将其从鼠标光标下移出。这会导致MouseLeave事件立即触发,再次将其放回鼠标光标下,再次触发MouseEnter事件,等等

您可以这样做:

    bool suppressMouseLeave;
    private void pictureBox1_MouseEnter(object sender, EventArgs e)
    {
        suppressMouseLeave = true;
        this.pictureBox1.Size = new Size(500, 500);
        pictureBox1.Location = new Point(this.Bounds.Width / 2,
                        this.Bounds.Height / 2);
        this.pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
        pictureBox1.BringToFront();
        //point the cursor to the new Position so that it's still kept on the pictureBox1
        //This is important because it makes your idea acceptable.
        //Otherwise you have to move your mouse onto your pictureBox and leave the 
        //mouse from it then to restore the pictureBox
        Cursor.Position = PointToScreen(new Point(pictureBox1.Left + 250, pictureBox1.Top + 250));
        suppressMouseLeave = false;
    }

    private void pictureBox1_MouseLeave(object sender, EventArgs e)
    {
        if(suppressMouseLeave) return;
        this.pictureBox1.Size = new Size(100, 100);
        pictureBox1.Location = new Point(12, 27);
    }

当您将鼠标悬停在PictureBox上并将其移动到窗体的中心时,就是将其从鼠标光标下移出。这会导致MouseLeave事件立即触发,再次将其放回鼠标光标下,再次触发MouseEnter事件,等等

您可以这样做:

    bool suppressMouseLeave;
    private void pictureBox1_MouseEnter(object sender, EventArgs e)
    {
        suppressMouseLeave = true;
        this.pictureBox1.Size = new Size(500, 500);
        pictureBox1.Location = new Point(this.Bounds.Width / 2,
                        this.Bounds.Height / 2);
        this.pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
        pictureBox1.BringToFront();
        //point the cursor to the new Position so that it's still kept on the pictureBox1
        //This is important because it makes your idea acceptable.
        //Otherwise you have to move your mouse onto your pictureBox and leave the 
        //mouse from it then to restore the pictureBox
        Cursor.Position = PointToScreen(new Point(pictureBox1.Left + 250, pictureBox1.Top + 250));
        suppressMouseLeave = false;
    }

    private void pictureBox1_MouseLeave(object sender, EventArgs e)
    {
        if(suppressMouseLeave) return;
        this.pictureBox1.Size = new Size(100, 100);
        pictureBox1.Location = new Point(12, 27);
    }

当您将鼠标悬停在PictureBox上并将其移动到窗体的中心时,就是将其从鼠标光标下移出。这会导致MouseLeave事件立即触发,从而将其再次放回鼠标光标下,从而导致