zoukankan      html  css  js  c++  java
  • winfrom 循环播放图片

    没啥新东西了,就是遍历和匹配文件名然后获取对象,放到picturebox里面

    选中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("请先选中需要查看的图片");
                }  

    循环播放

    循环播放用的线程执行,因为用进程执行的话,他会一直执行图片的循环而无法进行其他操作。

    在方法中启动线程执行方法,需要在构造中加上Control.CheckForIllegalCrossThreadCalls = false;

    然后就是点击按钮,创建并开启线程

    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--;
        }
      }
    }

    点击更改bf属性来更改播放状态

    if (bf)
    {
    bf = false;//停止
    btn_pause.Text = "停止";
    }
    else
    {
    bf = true;//播放
    btn_pause.Text = "播放";
    run = null;
    }

  • 相关阅读:
    每周进度条07
    软件需求模式阅读笔记06
    每周进度条06
    软件需求模式阅读笔记05
    Django之ModelForm组件
    Django的性能优化
    分页,缓存,序列化,信号
    Django补充——中间件、请求的生命周期等
    Git基础介绍和使用
    Django基础之三
  • 原文地址:https://www.cnblogs.com/big-lll/p/7753630.html
Copyright © 2011-2022 走看看