要在表单上显示动画图像,请执行以下操作;
1.)Drop a PictureBox on your Form.
2.)In the Properties Window of designer,change the image property so it contains the path to your image.
3.)Resize it as per your needs.
就是这样,现在尝试运行项目,如果没有抛出异常,您将在 PictureBox 中看到您的图像动画。
在项目执行过程中的任何时候,如果要更改图像,请使用以下语句;
pictureBox1.Load("Path to a new image");//Assuming you haven't renamed the PictureBox.
另外,如果您想手工完成,请继续阅读;
private void DisplayImage()
{
PictureBox pictureBox1=new PictureBox();
pictureBox1.Location=new Point(Use appropriate values to place the control);
this.Controls.Add(pictureBox1);
pictureBox1.Load("Path to a image to display");
}
当你不想让PictureBox显示的时候,像其他用户说的那样设置它的visible属性为false,这样;
pictureBox1.Visible=false;
并使用下面的代码将其取回;
pictureBox1.Visible=true;
更新:
要仅显示图像 5 秒,请执行此操作;
Drop a Timer on your Form.
Set its Interval property to 5000 Milliseconds.
Create a new Event for its Tick Event (locate Tick event in Events Window and double click it).
Next modify DisplayImage() so it looks like :
private void DisplayImage()
{
timer1.Start();
PictureBox pictureBox1=new PictureBox();
pictureBox1.Location=new Point(Use appropriate values to place the control);
this.Controls.Add(pictureBox1);
pictureBox1.Load("Path to a image to display");
}
Next define an integer field(outside all functions) named count,like this;
private int count=0;
Now modify timer1_Tick() event so it looks like below;
private void timer1_Tick(object sender, EventArgs e)
{
count++;
if (count == 5)
{
SourcePictureBox.Image = null;
count = 0;
}
}
这应该可以完成工作。还有什么,请告诉我。