C# 点击按钮1后,应打开和关闭时间间隔复选框

C# 点击按钮1后,应打开和关闭时间间隔复选框,c#,checkbox,C#,Checkbox,你能帮忙吗?在C语言中,单击按钮1后,选中复选框wmvfile时间间隔 应该打开和关闭 private void button1_Click(object sender, EventArgs e) { if (timercheckbox.Enabled == true) { timercheckbox = new Timer(); timercheckbox.Start(); timercheckbox.Interval = 10

你能帮忙吗?在C语言中,单击按钮1后,选中复选框wmvfile时间间隔 应该打开和关闭

private void button1_Click(object sender, EventArgs e)
{

    if (timercheckbox.Enabled == true)
    {
        timercheckbox = new Timer();
        timercheckbox.Start();
        timercheckbox.Interval = 10000; // 10 second

        if(timercheckbox.Enabled)
        {
            timercheckbox.Start();
            checkBoxWMVFile.Checked = true;
        }
        else
        {
            timercheckbox.Stop();
            checkBoxWMVFile.Checked = false;
        }
    }
}

据我所知,你需要这样的东西

private Timer _timer = new Timer();

    public Form1()
    {
        InitializeComponent();
        _timer.Interval = 10000;
        _timer.Tick += new EventHandler(_timer_Tick);
    }

    private void button1_Click(object sender, EventArgs e)
    {
        if (checkBox1.Checked)
        {
            checkBox1.Checked = false;
            if(_timer.Enabled)
                _timer.Stop();
        }
        else
        {
            checkBox1.Checked = true;
            if (!_timer.Enabled)
                _timer.Start();
        }
    }

    void _timer_Tick(object sender, EventArgs e)
    {
        //do something here
        throw new NotImplementedException();
    }

为了使代码正常工作,必须反转逻辑,即

private void button1_Click(object sender, EventArgs e)
{
    if(checkBoxWMVFile.Checked == false)//if the textbox is not checked
    {
        if (timercheckbox == null)//If this is the first time
        {
            timercheckbox = new Timer();//Create a timer
            timercheckbox.Interval = 10000; // Set the interval, before starting it.
            timercheckbox.Start();//Start it
        }
        else timercheckbox.Start();//If it is not the first time, just start it
        checkBoxWMVFile.Checked = true;//Check the checkbox
    }
    else//the checkbox is checked
    {
       timercheckbox.Stop();//Stop the timer
       checkBoxWMVFile.Checked = false;//Uncheck the checkbox
    }
}

此代码正常工作:

// InitializeComponent        
this.timercheckbox.Interval = 5000;
this.timercheckbox.Tick += new System.EventHandler(this.timercheckbox_Tick);

private void timercheckbox_Tick(object sender, EventArgs e)
{
    checkBoxWMVFile.Checked = false;
    checkBoxWMVFile.Checked = true;
}

private void button1_Click(object sender, EventArgs e)
{
    if( timercheckbox.Enabled == true )
    {            
        timercheckbox.Enabled = false;
        button1.Text = "Start Auto save";
    }
    else
    {
        timercheckbox.Interval = (int)numericChnageTime.Value;
        timercheckbox.Enabled = true;
        checkBoxWMVFile.Checked = true;
        button1.Text = "Stop Auto save";
    }
}

请提供有关您的具体问题的更多信息,而不是要求完整的解决方案!要理解你的问题几乎是不可能的。请澄清您到底想完成什么?要响应计时器超时,您需要添加超时处理程序timercheckbox.appeased+=timercheckbox\u appeased;如果你澄清你的问题,我可能会给你一个正确的答案。我使用应用程序medialooks videomixer SDK,我不会在1小时后输入自动录像。所以我想检查一下BoxFileWMV每小时打开和关闭一次谢谢你的回答。当我在你的应用程序中输入代码并按下按钮1 10秒以显示错误消息时:抛出新的NotImplementedException;方法或操作未实现。Martin,在粘贴到项目中之前,您没有阅读@steavy发布的代码,是吗?看看“定时器滴答”方法。马丁,你必须实现“定时器滴答”方法。我留下了一个例外,因为我不知道你在申请中到底在做什么。也许你需要在这个方法中重置定时器,但也许你需要一些额外的逻辑,所以这取决于你。斯蒂维,嗨,威尔达纳!我不是程序员,我只是想简化我的工作。。。App videomixer从摄像机录制视频。我想每小时刷新一次记录并创建一个单独的视频文件。我以为我们用的是一个睡眠系统,但它不起作用。唯一的选择是时间间隔,但不知道它。。。。最后一次尝试。。。如何实现_timer_Tick方法。只需选择Timer中的工具箱并将其转换为_Timer?因为我试过了,什么都没有…嗨,雷格。我试过你的密码。单击按钮1后,录制在10秒后打开,但它仍然/视频录制仍然/。还有别的吗?给Codesparkle:嗨,对不起。应用程序。Videomixer通过单击复选框FileWMV录制视频,视频将一直录制。当我点击按钮1时,我想每1小时录制一次视频。我已将视频保存了24小时除以1小时。该代码是button1_click事件的示例。正如steavy所演示的,在计时器事件中经过时间之后,必须定义要执行的操作。我认为解决问题的一个简单方法是从计时器事件中调用button1_click事件。