Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么当我运行计时器时,刻度(轨迹条小线)的数量在变化?_C# - Fatal编程技术网

C# 为什么当我运行计时器时,刻度(轨迹条小线)的数量在变化?

C# 为什么当我运行计时器时,刻度(轨迹条小线)的数量在变化?,c#,C#,我有48帧/图像。当我点击播放(按钮14)时,它会自动在图像中移动 但我也希望轨迹栏和计时器一起移动。但是如果我把TrackBar1.Value=\u indx;在timer3 tick事件中,当它一次又一次地播放时,如果我有48帧,轨迹栏的值会发生变化,因此现在轨迹栏只有15个刻度,然后当它到达右侧的末端时停止 我想要的是,如果我单击“播放”,它将一遍又一遍地在图像中运行,如果我单击“暂停”,然后继续,直到我停下来 事实上,轨迹栏的值会发生变化,因为在timer3 tick事件中,我也会执行_

我有48帧/图像。当我点击播放(按钮14)时,它会自动在图像中移动

但我也希望轨迹栏和计时器一起移动。但是如果我把TrackBar1.Value=\u indx;在timer3 tick事件中,当它一次又一次地播放时,如果我有48帧,轨迹栏的值会发生变化,因此现在轨迹栏只有15个刻度,然后当它到达右侧的末端时停止

我想要的是,如果我单击“播放”,它将一遍又一遍地在图像中运行,如果我单击“暂停”,然后继续,直到我停下来

事实上,轨迹栏的值会发生变化,因为在timer3 tick事件中,我也会执行_indx++;当它在轨迹栏上显示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;
}
private void btnPlay\u单击(对象发送方,事件参数e)
{
_indx=0;
DirectoryInfo dir=新的DirectoryInfo(sf);
如果(_files==null)
_文件=新列表();
FileInfo[]fi=dir.GetFiles(“*.bmp”);
_AddRange文件(fi);
_files=_files.OrderBy(f=>f.LastWriteTime.ToList();
按钮14.ForeColor=颜色。红色;
按钮13.ForeColor=颜色。黑色;
按钮12.ForeColor=颜色。黑色;
timer3.Start();
按钮13.启用=真;
按钮13.Text=“暂停”;
按钮12.Enabled=true;
}
私有无效计时器3_刻度(对象发送方,事件参数e)
{
尝试
{
Image iOLd=this.pictureBox1.Image;
Image img=Image.FromFile(\u files[\u indx].FullName);
trackBar1.Value=\u indx;
label23.Text=\u文件[\u indx].Name;
this.pictureBox1.Image=img;
如果(iOLd!=null)
iOLd.Dispose();
_indx++;
如果(\u indx>=\u files.Count)
_indx=0;
时间间隔=10;
timer3.Start();
}
抓住
{
}
}
私有无效btnPause_单击(对象发送者,事件参数e)
{
按钮13.ForeColor=颜色。红色;
按钮14.ForeColor=颜色。黑色;
timer3.Stop();
如果(按钮13.Text==“继续”)
{
timer3.Start();
按钮13.Text=“暂停”;
返回;
}
如果(按钮13.Text==“暂停”)
{
timer3.Stop();
按钮13.Text=“继续”;
}
}
私有void btnStop_单击(对象发送方,事件参数e)
{
trackBar1.Value=0;
Image iOLd=this.pictureBox1.Image;
Image img=Image.FromFile(\u files[0].FullName);
this.pictureBox1.Image=img;
如果(iOLd!=null)
iOLd.Dispose();
按钮13.Text=“暂停”;
timer3.Stop();
_indx=0;
label23.Text=\u文件[\u indx].Name;
按钮12.ForeColor=颜色。红色;
按钮14.ForeColor=颜色。黑色;
按钮13.启用=错误;
}
按钮14是播放按钮13是暂停/继续,按钮12是停止。问题是如果我不使用trackBar1.Value=\u indx;轨迹栏根本不动。如果我不做indx++;那什么都不行


_文件是列表且_indx是int

FYI:如果您将按钮重命名为类似于
btnPlay
,这将非常有帮助(对您和我们)。每次单击“播放”时,通过创建一个新的_文件列表实例来解决此问题,并在计时器中添加一个新行,在if _indx>=\u files.count内打勾,然后再创建trackBar1.Value=0;