-1

手伝ってくれますか?C# では、button1 をクリックした後、checkBoxWMVFile (時間間隔) のオンとオフを切り替える必要があります。

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

3 に答える 3

0

このコードは正しく機能します:

// 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";
    }
}
于 2012-07-23T07:16:46.603 に答える
0

私が理解したように、あなたはこのようなものが必要です

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();
    }
于 2012-07-21T10:57:26.050 に答える
0

コードが機能するためには、ロジックを逆にする必要があります。

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
    }
}
于 2012-07-21T11:28:53.283 に答える