图片框中的图像切换 [英] Image Switching in a Picture Box
本文介绍了图片框中的图像切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
好吧我的问题可能有点模糊。假设我有两个图像i-e图像1和图像2,我希望它们在同一个图片框中一个接一个地显示在图片框1中。现在,一种可能不是一种聪明方式的方法是
Hello
OK my question might be a bit vague. Say i have two images i-e "image 1" and "image 2" and i want both of them to be displayed one after the other one in the same picturebox say picturebox1. Now one way that might not be a smart way of doing it is
while(true)
{
picturebox1.image=image 1;
picturebox1.refresh();
pictureboz1.image=image 2;
picturebox1.refresh();
}
还有其他办法吗?
无论如何谢谢
Is there any other way of doing it.?
Thanks anyways
推荐答案
嗯,不,这不是一个聪明的方法 - 有几个原因:
首先,它可能根本不显示任何图像,因为它坐在在一个循环中改变它们并且永远不会有机会为任何事物做Paint事件...
其次,因为如果它确实显示了什么,它会被更快地替换,用户可能不会完全注意到它...
很难确切地说要做什么,因为你没有指定你正在运行的环境,但使用PictureBox暗示WinForms,所以我将继续:
1)在表单中添加计时器
,并将其设置为间隔
属性为1000 - 这是一秒间隔。启动计时器。
3)在表单类中添加private bool
字段,将其命名为showFirst
并将其设置为true
2)处理Timer.Tick
事件,并执行此操作:
Well, no, that's not a smart way - for a couple of reasons:
Firstly, it'll probably not show any image at all because it sits in a loop changing them and never gets a chance to do the Paint event for anything...
Secondly, because if it did show anything, it would be replaced so quickly that the user probably wouldn't notice it at all...
It's difficult to say exactly what to do, because you don;t specify the environment you are running in, but the use of PictureBox implies WinForms, so I'll go with that:
1) Add aTimer
to your form, and set it'sInterval
property to 1000 - that's a one second interval. Start the timer.
3) Add aprivate bool
field to your form class, call itshowFirst
and set it totrue
2) Handle theTimer.Tick
event, and do this:
pictureBox1.Image = showFirst ? image1 : image2;
showFirst = !showFirst;
这应该每秒更改一次图像。
That should change your image every second.
尝试其中一些链接 [ ^ ]。
这篇关于图片框中的图像切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文