每天从一个目录里随机选择一个图片显示!怎么做?
解决方案 »
- 数据集填充fill(dataset,string)中的string 是指表名称吗?
- 求教获取已知句柄的Internet Explorer_Server内容
- 刻录程序报错,调用COM组件失败的问题
- 新手求助
- WinFrom 代码设置GridView单元格的背景色
- asp.net 多附件上传??
- this.btnUpdate.Click += new System.EventHandler(this.btnUpdate_Click);(20分相送)
- 怎样判断在TREEVIEW控件中的checkbox是否被选中?
- c#数据库开发用哪本书好? 哪里有下载? 谢谢!
- 请各位大哥帮忙!我要找一些关于C#方面的题目!
- 简单选择排序 问题
- 求教C#与批处理参数传递问题?
存到数组中
在system.io
中好像是dictory.getfiles
在获取数组的数量
用随机数round产生一个不大于这个数的整数!
通过随数在数组中获得图片名!
FileInfo[] files = dInfo.GetFiles("*.jpg|*.gif|*.png");
if(files != null && files.Length > 0)
{
int index = random.Next(0,files.Length);
FileStream stream = files[index].Open();
...
}
public Image GetRandomImage()
{
Random rand = new Random((int)DateTime.Now.Ticks);
string[] pictures = Directory.GetFiles("C:\\Images");
Image img = null;
if (pictures.Length > 0)
{
int index = Math.abs(rand.Next()) % pictures.Length;
img = Image.FromFile(pictures[index]);
}
return img;
}
2. System.Random() 获取一个在数组大小范围内的随机数,以此为索引值取数组中的对应值用于显示