思路:
1.创建定时器
2.设置背景图片
C#设置背景图片变换
通过发送请求方式获取图片
//设置背景图片 变动
public static void pictureShow(UIPanel picturePl)
{
int i = 1;
Timer pictureTimer = new Timer();
pictureTimer.Enabled = true;
pictureTimer.Interval = 5000;
pictureTimer.Tick += new EventHandler((s, x) =>
{
string url = string.Empty;
if (i==1)
{
url = string.Format(@"http://www.图片.cn/images/1.jpg");
}
else if (i==2)
{
url = string.Format(@"http://www.图片.cn/images/2.jpg");
}
else if (i == 3)
{
url = string.Format(@"http://www.图片.cn/images/3.jpg");
}
else if (i == 4)
{
url = string.Format(@"http://www.图片.cn/images/4.jpg");
}
else if (i == 5)
{
url = string.Format(@"http://www.图片.cn/images/5.jpg");
}
else
{
i = 1;
url = string.Format(@"http://www.图片.cn/images/6.jpg");
}
setPicture(url, picturePl);
i++;
});
}
public static void setPicture(string imgUrl, UIPanel picturePl)
{
System.Net.WebRequest webreq = System.Net.WebRequest.Create(imgUrl);
System.Net.WebResponse webres = webreq.GetResponse();
using (System.IO.Stream stream = webres.GetResponseStream())
{
picturePl.BackgroundImage = Image.FromStream(stream);
}
}
亲测有效