没啥新东西了,就是遍历和匹配文件名而后获取对象,放到picturebox里面spa
选中listview中想要查看的图片,而后点击查看按钮,进行↓代码。线程
if (listView1.SelectedItems.Count > 0)
{
string name = listView1.Items[listView1.SelectedIndices[0]].Text;//选中的文件名
string dpath = fName.Substring(0, fName.LastIndexOf("\\"));//去除掉文件名
DirectoryInfo dti = new DirectoryInfo(dpath); FileInfo[] file = dti.GetFiles(name);//查找名称和name同样的图片 Bitmap bmp = new Bitmap(file[0].FullName); pictureBox1.Image = bmp; pictureBox1.Refresh(); getgridv(name); } else { MessageBox.Show("请先选中须要查看的图片"); }
循环播放用的线程执行,由于用进程执行的话,他会一直执行图片的循环而没法进行其余操做。code
在方法中启动线程执行方法,须要在构造中加上Control.CheckForIllegalCrossThreadCalls = false;对象
而后就是点击按钮,建立并开启线程blog
if (run==null)
{
Thread td = new Thread(xunhuan);
td.Start();
}进程
int i = 0; bool bf = true;//判断是否暂停播放 string run = null;//用来判断线程是否在运行 public void xunhuan() { run = "run"; if (listView1.SelectedItems.Count > 0)//若是listview有选中项就从选中项开始循环 { while (true) { if (!bf) { break; } if (i >= listView1.Items.Count) { i = 0; break; } if (i >= listView1.SelectedIndices[0]) { cycle(i);//加载图片 System.Threading.Thread.Sleep(300); } i++; } } if (i == 0) { int j = 0; while (true) { if (!bf) { break; } if (j >= listView1.Items.Count) { j=0; } //listView1.Items[j].Focused = true; cycle(listView1.Items[j].Text); System.Threading.Thread.Sleep(300); j++; } } }
还有一个倒叙循环,和上面基本同样,也是经过线程执行,判断bool是否暂停。图片
private void daoxu()
{
run = "daorun";
int dx = listView1.Items.Count;
if (listView1.SelectedItems.Count > 0)//若是listview有选中项就从选中项开始循环
{
while (true)
{
if (!bf)
{
break;
}
if (dx < 0)
{
break;
}
if (dx <= listView1.SelectedIndices[0])
{
cycle(dx);//加载图片
System.Threading.Thread.Sleep(300);
}
dx--;
}
}
if (dx == listView1.Items.Count)
{
int j = listView1.Items.Count - 1;
while (true)
{
if (!bf)
{
break;
}
if (j < 0)
{
break;
}
//listView1.Items[j].Focused = true;
cycle(listView1.Items[j].Text);
System.Threading.Thread.Sleep(300);
j--;
}
}
}get
点击更改bf属性来更改播放状态string
if (bf)
{
bf = false;//中止
btn_pause.Text = "中止";
}
else
{
bf = true;//播放
btn_pause.Text = "播放";
run = null;
}it