如何将winform 中的图片设置为反复移动

如何将winform 中的图片设置为反复移动,第1张

首先需要有一个timer控件
然后设置一个全局变量 bool key=true;
然后再timer的tick事件里写
private void timer1_Tick(object sender, EventArgs e)
{
if (key == true)
{
if (pictureBox1Left > 0)
{
pictureBox1Left -= 1;
}
else
{
key = false;
}
}
if(key==false)
{
if (pictureBox1Right < thisWidth-1)
{
pictureBox1Left += 1;
}
else
{
key = true;
}
}
}
当然用的是pictureBox控件,可以自己换别的 速度可以调节timer属性

这是应为你读取数据库和控制是在同一个线程里,这样是按顺序完成的,你读取数据库的结果没有返回就执行不到pictureBoxEnabled=true这一步。
如果你不是在新窗口放置gif的话可以先显示再读取数据库,否则的话只能用多线程的方法去解决了。

只用一个timer控件,设置enable属性为true;Interval为你所想要让两张交替变换的时间间隔。将两张放到imagelist控件中,然后在timer控件tick事件中写下面代码:
if (thispictureBox1Image==thisimageList1Images[0])
{
thispictureBox1Image = thisimageList1Images[1];
}
else
{
thispictureBox1Image = thisimageList1Images[0];
}

<script language="javascript" type="text/javascript">
//滚动展示 Start
var counts = 4;
//大图//
img1 = new Image();
img1src = 'images/1jpg';
img2 = new Image();
img2src = 'images/2jpg';
img3 = new Image();
img3src = 'images/3jpg';
img4 = new Image();
img4src = 'images/4jpg';


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/13400224.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-07-29
下一篇 2023-07-29

发表评论

登录后才能评论

评论列表(0条)

保存