0

我有 48 帧/图像。当我点击播放(button14)时,我做了什么,它将自动在图像中移动。

但我也希望 trackBar Bar 与计时器一起移动。但如果我让 TrackBar1.Value = _indx; 在 timer3 滴答事件中,然后在它一遍又一遍地播放之后,如果我有 48 帧,trackBar 的值会发生变化,所以现在 trackBar 只有 15 个滴答声,然后当它到达右侧的末尾时它会停止。

我想要的是,如果我点击播放它会一遍又一遍地运行图像,如果我点击暂停然后继续直到我停止。

事实上 trackBar 的值在 timer3 滴答事件中发生了变化,我也做了 _indx++; 当它在 trackBar 上的 15 帧时,它也最终停止而不是继续。

private void btnPlay_Click(object sender, EventArgs e)
{
    _indx = 0;
    DirectoryInfo dir = new DirectoryInfo(sf);

    if (_files == null)
        _files = new List<FileInfo>();

    FileInfo[] fi = dir.GetFiles("*.bmp");
    _files.AddRange(fi);

    _files = _files.OrderBy(f => f.LastWriteTime).ToList();
    button14.ForeColor = Color.Red;
    button13.ForeColor = Color.Black;
    button12.ForeColor = Color.Black;
    timer3.Start();
    button13.Enabled = true;
    button13.Text = "Pause";
    button12.Enabled = true;
}

private void timer3_Tick(object sender, EventArgs e)
{
    try
    {
        Image iOLd = this.pictureBox1.Image;
        Image img = Image.FromFile(_files[_indx].FullName);
        trackBar1.Value = _indx;
        label23.Text = _files[_indx].Name;
        this.pictureBox1.Image = img;

        if (iOLd != null)
            iOLd.Dispose();

        _indx++;

        if (_indx >= _files.Count)
            _indx = 0;

        timer3.Interval = 10;
        timer3.Start();
    }
    catch
    {

    }
}

private void btnPause_Click(object sender, EventArgs e)
{
    button13.ForeColor = Color.Red;
    button14.ForeColor = Color.Black;
    timer3.Stop();
    if (button13.Text == "Continue")
    {
        timer3.Start();
        button13.Text = "Pause";
        return;
    }

    if (button13.Text == "Pause")
    {
        timer3.Stop();
        button13.Text = "Continue";
    }
}

private void btnStop_Click(object sender, EventArgs e)
{
    trackBar1.Value = 0;
    Image iOLd = this.pictureBox1.Image;
    Image img = Image.FromFile(_files[0].FullName);
    this.pictureBox1.Image = img;
    if (iOLd != null)
        iOLd.Dispose();
    button13.Text = "Pause";
    timer3.Stop();
    _indx = 0;
    label23.Text = _files[_indx].Name;
    button12.ForeColor = Color.Red;
    button14.ForeColor = Color.Black;
    button13.Enabled = false;
}

Button14 是 Play button13 是 Pause/Continue 而 Button12 是 Stop 问题是如果我不做 trackBar1.Value = _indx; trackBar 根本不会移动。如果我不制作_indx++;那么什么都行不通。

_files 是 List 而 _indx 是 int

4

0 回答 0