C# 如何显示图像预览?更改pictureBox大小并将其移动到窗体中心的步骤

C# 如何显示图像预览?更改pictureBox大小并将其移动到窗体中心的步骤,c#,winforms,C#,Winforms,这是表1中的代码: private void timer1_Tick(object sender, EventArgs e) { try { pictureBox1.Load(file_array_satellite[file_indxs_satellite]); //label12.Visible = true; //label12.

这是表1中的代码:

private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {

                pictureBox1.Load(file_array_satellite[file_indxs_satellite]);
                //label12.Visible = true;
                //label12.Text = "Satellite files date and time: " + File.GetCreationTime(file_array_satellite[file_indxs_satellite]);
                file_indxs_satellite = file_indxs_satellite - 1;
                //pictureBox1.Load(file_array[file_indexs]);
                //label10.Visible = true;
                //label10.Text = "Radar files date and time: " + File.GetCreationTime(file_array[file_indexs]);
                file_indxs_satellite = file_indxs_satellite - 1;
                if (file_indxs_satellite < 0)
                {
                    file_indxs_satellite = file_array_satellite.Length - 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*.*");
            for (int i = 0; i < file_array_satellite.Length; i++)
            {
                Image s = new Bitmap(file_array_satellite[i]);
                s = resizeImage(s, new Size(100, 100));
                s.Save(UrlsPath + "Changed" + i.ToString("D6") + ".jpg");
            }
            file_array_satellite = Directory.GetFiles(UrlsPath, "Changed*.*");
            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;
            }
        }

        public static Image resizeImage(Image imgToResize, Size size)
        {
            return (Image)(new Bitmap(imgToResize, size));
        }

        private void pictureBox1_MouseEnter(object sender, EventArgs e)
        {

        }
在构造函数中:

localFilename = @"d:\localpath\";
UrlsPath = @"d:\localpath\Urls\";
我想做的是,当我将鼠标移到pictureBox1区域上时,pictureBox的大小将调整为例如400x400,并将在pictureBox1中以调整大小的大小显示图像,在本例中为400x400

就像预演一样。当我用鼠标移动时,动画将继续移动/播放,但图片框将在窗体的中间,并且像400 x400。

更大的尺寸。 我怎么做?在pictureBox1\u鼠标事件中我应该做什么

编辑**

我试过这个:

private void pictureBox1_MouseEnter(object sender, EventArgs e)
        {
            pictureBox1.Location = new Point(this.Bounds.Width / 2,
                            this.Bounds.Height / 2);
            this.pictureBox1.Size = new Size(500, 500);
            this.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
            pictureBox1.BringToFront();
        }
但pictureBox不在中间,大小不变。为什么? 在原来的图片盒大小是100100也在硬盘上的文件,我把他们改为100100,它的工作良好

一旦我将鼠标移到pictureBox上,它就不会移动到中心,也不会调整大小到500500

表格1的大小是800600

我希望图片盒显示在表单的中心,尺寸更大,500500或700500


怎么了?

您应该通过
PictureBox.SizeMode
调整图像大小,这样图像将填充PictureBox。然后使用
MouseEnter
MouseLeave
事件调整PictureBox的大小。它的大小将随里面的图片一起调整。

rum我编辑了我的问题,添加了我所做的mouseenter事件的一部分,但它不起作用。请尝试
this.pictureBox1.SizeMode=PictureBoxSizeMode.StretchImage
this.pictureBox1.SizeMode=PictureBoxSizeMode.Zoom
private void pictureBox1_MouseEnter(object sender, EventArgs e)
        {
            pictureBox1.Location = new Point(this.Bounds.Width / 2,
                            this.Bounds.Height / 2);
            this.pictureBox1.Size = new Size(500, 500);
            this.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
            pictureBox1.BringToFront();
        }