图片框中的图像切换 [英] Image Switching in a Picture Box

查看:75
本文介绍了图片框中的图像切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

好​​吧我的问题可能有点模糊。假设我有两个图像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 a Timer to your form, and set it's Interval property to 1000 - that's a one second interval. Start the timer.
3) Add a private bool field to your form class, call it showFirst and set it to true
2) Handle the Timer.Tick event, and do this:
pictureBox1.Image = showFirst ? image1 : image2;
showFirst = !showFirst;

这应该每秒更改一次图像。

That should change your image every second.


尝试其中一些链接 [ ^ ]。


这篇关于图片框中的图像切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆