这是 Form1 中的代码:
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)
{
}
在表格 1 的顶部:
string[] file_array_satellite;
int file_indxs_satellite;
在构造函数中:
localFilename = @"d:\localpath\";
UrlsPath = @"d:\localpath\Urls\";
我想要做的是,当我将鼠标移到pictureBox1 区域上时,pictureBox 将被调整为例如 400x400,并且会以调整后的大小在这种情况下为 400x400 显示 pictureBox1 中的图像。
喜欢预览。当我用鼠标移动时,动画将继续移动/播放,但图片框将位于表单的中间,并且尺寸更大,例如 400x400 。
我该怎么做 ?我应该在 pictureBox1_MouseEnter 事件中做什么?
编辑**
试过这个:
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不在中心,大小没有变化。为什么 ?原来的pictureBox大小是100,100,硬盘上的文件我把它们改成100,100,效果很好!
一旦我将鼠标移到图片框上,它就不会移动到中心,也不会调整到 500,500。
form1 大小为 800,600
我希望图片框显示在表格的中心并且尺寸更大 500,500 或 700,500
怎么了 ?