这样做出来的是一下全输出来了,我想做的效果是,窗体显示,然后图片一张一张的摆放到窗体上,并且图片一直循环着往外贴,不停止。不会了,求指点private void Form1_Load(object sender, EventArgs e)
{
string s1 = @"E:\工作\加载\加载\img\1.JPG";
string s2 = @"E:\工作\加载\加载\img\2.JPG";
string s3 = @"E:\工作\加载\加载\img\3.JPG";
string s4 = @"E:\工作\加载\加载\img\4.JPG";
string s5 = @"E:\工作\加载\加载\img\5.JPG";
string s6 = @"E:\工作\加载\加载\img\6.JPG";
Random rnd = new Random();
string []imgs=new string[]{s1,s2,s3,s4,s5,s6};
string[] imgRnds=new string[imgs.Length]; //随机打乱后的数组//>>随机打乱
int k=imgs.Length;
int i=0;
while(k>0)
{
int j=rnd.Next(k);
imgRnds[i]=imgs[j];
imgs[j]=imgs[k-1];
k--;
i++;
//System.Threading.Thread.Sleep(1000); //停一秒钟
//Application.DoEvents();
}
//>>放到窗体随机位置上
foreach (string s in imgRnds)
{
PictureBox pic = new PictureBox();
pic.Image = Image.FromFile(s); //这句你根据实际路径写
int left = rnd.Next(this.Width - pic.Width);
int top = rnd.Next(this.Height - pic.Height);
pic.Location = new Point(left, top);
this.Controls.Add(pic);
}
}
{
string s1 = @"E:\工作\加载\加载\img\1.JPG";
string s2 = @"E:\工作\加载\加载\img\2.JPG";
string s3 = @"E:\工作\加载\加载\img\3.JPG";
string s4 = @"E:\工作\加载\加载\img\4.JPG";
string s5 = @"E:\工作\加载\加载\img\5.JPG";
string s6 = @"E:\工作\加载\加载\img\6.JPG";
Random rnd = new Random();
string []imgs=new string[]{s1,s2,s3,s4,s5,s6};
string[] imgRnds=new string[imgs.Length]; //随机打乱后的数组//>>随机打乱
int k=imgs.Length;
int i=0;
while(k>0)
{
int j=rnd.Next(k);
imgRnds[i]=imgs[j];
imgs[j]=imgs[k-1];
k--;
i++;
//System.Threading.Thread.Sleep(1000); //停一秒钟
//Application.DoEvents();
}
//>>放到窗体随机位置上
foreach (string s in imgRnds)
{
PictureBox pic = new PictureBox();
pic.Image = Image.FromFile(s); //这句你根据实际路径写
int left = rnd.Next(this.Width - pic.Width);
int top = rnd.Next(this.Height - pic.Height);
pic.Location = new Point(left, top);
this.Controls.Add(pic);
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货