コード例 #1
0
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            switch (keyData)
            {
            case Keys.O:
                ReadList();
                if (picList.Count() != 0)
                {
                    PlayList();
                }
                return(true);

            case Keys.Left:
            case Keys.Up:
                ///这里有一个不在播放状态下按方向键会崩溃的问题
                if (iPic > 1)
                {
                    iPic--;
                    picPath = p.path + "\\" + p.prefix + " (" + iPic.ToString() + ")." + p.extension;
                    this.pictureBox1.Load(picPath);
                }
                timer.Stop();
                timer.Start();
                return(true);

            case Keys.Right:
            case Keys.Down:
                if (iPic < p.numPic)
                {
                    iPic++;
                    picPath = p.path + "\\" + p.prefix + " (" + iPic.ToString() + ")." + p.extension;
                    this.pictureBox1.Load(picPath);
                }
                timer.Stop();
                timer.Start();
                return(true);

            case Keys.PageUp:
                iGroup  = (iGroup + picList.Count - 1) % picList.Count();
                p       = picList[iGroup];
                iPic    = 1;
                picPath = p.path + "\\" + p.prefix + " (" + iPic.ToString() + ")." + p.extension;
                this.pictureBox1.Load(picPath);
                timer.Interval = (int)(p.stepTime * 1000);
                return(true);

            case Keys.PageDown:
                iGroup  = (iGroup + 1) % picList.Count();
                p       = picList[iGroup];
                iPic    = 1;
                picPath = p.path + "\\" + p.prefix + " (" + iPic.ToString() + ")." + p.extension;
                this.pictureBox1.Load(picPath);
                timer.Interval = (int)(p.stepTime * 1000);
                return(true);
            }
            return(false);
        }
コード例 #2
0
        private void ReadList()
        {
            OpenFileDialog file = new OpenFileDialog();

            file.InitialDirectory = ".";
            file.Filter           = "文本文件|*.txt";
            file.ShowDialog();
            if (file.FileName != string.Empty)
            {
                try
                {
                    string       pathname = file.FileName;                 //获得文件的绝对路径
                    Stream       s        = file.OpenFile();
                    StreamReader sr       = new StreamReader(s);
                    string       text;
                    text = sr.ReadLine();
                    while (text != null)
                    {
                        if (text == string.Empty || text.StartsWith("*") == true)
                        {
                            text = sr.ReadLine();
                            continue;
                        }
                        string[] split = text.Split(new Char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);

                        PicGroup p = new PicGroup
                        {
                            prefix    = split[0],
                            extension = split[1],
                            stepTime  = double.Parse(split[2]),
                            path      = pathname.Substring(0, pathname.LastIndexOf('\\'))                             //不包含最后的反斜杠
                        };

                        int iFile = 1;
                        while (File.Exists(p.path + "\\" + p.prefix + " (" + iFile.ToString() + ")." + p.extension))
                        {
                            iFile++;
                        }
                        p.numPic = iFile - 1;

                        picList.Add(p);
                        text = sr.ReadLine();
                    }
                    sr.Close();
                    s.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
コード例 #3
0
        private void ReadList(string listPath)
        {
            try
            {
                Stream       s  = File.Open(listPath, FileMode.Open);
                StreamReader sr = new StreamReader(s);
                string       text;
                text = sr.ReadLine();
                while (text != null)
                {
                    if (text == string.Empty || text.StartsWith("*") == true)
                    {
                        text = sr.ReadLine();
                        continue;
                    }
                    string[] split = text.Split(new Char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    PicGroup p     = new PicGroup
                    {
                        prefix    = split[0],
                        extension = split[1],
                        stepTime  = double.Parse(split[2]),
                        path      = listPath.Substring(0, listPath.LastIndexOf('\\'))                         //不包含最后的反斜杠
                    };

                    int iFile = 1;
                    while (File.Exists(p.path + "\\" + p.prefix + " (" + iFile.ToString() + ")." + p.extension))
                    {
                        iFile++;
                    }
                    p.numPic = iFile - 1;


                    picList.Add(p);
                    text = sr.ReadLine();
                }
                sr.Close();
                s.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #4
0
        private void PlayList()
        {
            int currentIndex;

            for (int i = 0; i < picList.Count; i++)
            {
                currentIndex = random.Next(0, picList.Count - i);
                PicGroup p_temp = picList[currentIndex];
                picList[currentIndex]          = picList[picList.Count - 1 - i];
                picList[picList.Count - 1 - i] = p_temp;
            }

            timer.AutoReset = true;
            iGroup          = 0;

            p       = picList[iGroup];
            iPic    = 1;
            picPath = p.path + "\\" + p.prefix + " (" + iPic.ToString() + ")." + p.extension;
            this.pictureBox1.Load(picPath);
            timer.Interval = (int)(p.stepTime * 1000);
            timer.Start();

            timer.Elapsed += new System.Timers.ElapsedEventHandler((sender, e) =>
            {
                if (iPic < p.numPic)
                {
                    iPic++;
                    picPath = p.path + "\\" + p.prefix + " (" + iPic.ToString() + ")." + p.extension;
                    this.pictureBox1.Load(picPath);
                }
                else
                {
                    iGroup  = (iGroup + 1) % picList.Count();
                    p       = picList[iGroup];
                    iPic    = 1;
                    picPath = p.path + "\\" + p.prefix + " (" + iPic.ToString() + ")." + p.extension;
                    this.pictureBox1.Load(picPath);
                    timer.Interval = (int)(p.stepTime * 1000);
                }
            });
        }