C# 在picturebox中动态更改图像
我想运行一段代码,在窗体关闭之前不断更改picturebox(如旋转的螺旋桨)的图片 我设法用事件处理程序更改了PictureBox的图片,但我不知道如何进行C# 在picturebox中动态更改图像,c#,dynamic,picturebox,C#,Dynamic,Picturebox,我想运行一段代码,在窗体关闭之前不断更改picturebox(如旋转的螺旋桨)的图片 我设法用事件处理程序更改了PictureBox的图片,但我不知道如何进行 public Form1() { InitializeComponent(); this.Controls.Add(pb); } PictureBox pb = new PictureBox { Location = new Point(0, 0),
public Form1()
{
InitializeComponent();
this.Controls.Add(pb);
}
PictureBox pb = new PictureBox
{
Location = new Point(0, 0),
SizeMode = PictureBoxSizeMode.Zoom,
Size = new Size(300,300),
ImageLocation = @"E:\folder\gas_jo.png"
};
private void Form1_Click(object sender, EventArgs e)
{
if (pb.ImageLocation == @"E:\folder\gas_jo.png")
{
pb.ImageLocation =@"E:\folder\gas_jo_1.png";
}
else if (pb.ImageLocation == @"E:\folder\gas_jo_1.png")
{
pb.ImageLocation = @"E:\folder\gas_jo.png";
}
}
你还想做什么?在无限循环中改变画面。当我启动程序时,我希望图片自动从gas_jo.png更改为gas_jo_1.png,依此类推。你想在几秒钟内更改pictureBox的图像吗?没错,如果我不清楚,很抱歉,这就是我要找的,谢谢!
System.Windows.Forms.Timer timer;
public Form1()
{
InitializeComponent();
this.Controls.Add(pb);
timer = new System.Windows.Forms.Timer();
timer.Interval = 1000;
timer.Tick += (sender, args) => {
if (pb.ImageLocation == @"E:\folder\gas_jo.png")
{
pb.ImageLocation =@"E:\folder\gas_jo_1.png";
}
else if (pb.ImageLocation == @"E:\Real-time_Imi\gas_jo_1.png")
{
pb.ImageLocation = @"E:\Real-time_Imi\gas_jo.png";
}
};
timer.Start();
}
PictureBox pb = new PictureBox
{
Location = new Point(0, 0),
SizeMode = PictureBoxSizeMode.Zoom,
Size = new Size(300,300),
ImageLocation = @"E:\folder\gas_jo.png"
};
string[] pictureBoxArray = new string[] { @"E:\folder\gas_jo.png", @"E:\folder\gas_jo_1.png", @"E:\folder\gas_jo_2.png" };
int pctIndex = 0;
private void timer1_Tick(object sender, EventArgs e)
{
pb.ImageLocation = pictureBoxArray[pctIndex];
pctIndex ++;
if(pctIndex==pictureBoxArray.Length)
pctIndex =0 ;
}