0

timer1 が別の timer2 をアクティブにしてから停止するプログラムを作成しています。そして、ここに問題があります。最初にTimer1の目盛りの2つが書き出され、次にタイマー2の2つが書き込まれ、次に2が乗算されるため、次回は4、次に8、16というように、1つのtimer2よりも1つのtimer1になりたいだけですその後、最初からやり直し、何が問題なのかわかりません。

private void buttonStart_Click(object sender, EventArgs e)
{
    buttonStart.Enabled = false;
    buttonStop.Enabled = true;

    timer1.Tick += new EventHandler(timer1_Tick); 
    timer1.Interval = (1000);             
    timer1.Enabled = true;                       
    timer1.Start();

}

private void buttonStop_Click(object sender, EventArgs e)
{
    buttonStart.Enabled = true;
    buttonStop.Enabled = false;

    timer1.Stop();
    timer2.Stop();
}

private void LogWrite(string txt)
{
    textBoxCombatLog.AppendText(txt + Environment.NewLine);
    textBoxCombatLog.SelectionStart = textBoxCombatLog.Text.Length;
}

private void timer1_Tick(object sender, EventArgs e)
{
    LogWrite(TimeDate + "player hit");

    timer1.Stop();

    timer2.Tick += new EventHandler(timer2_Tick);
    timer2.Interval = (1000);
    timer2.Enabled = true;
    timer2.Start();


}

private void timer2_Tick(object sender, EventArgs e)
{
    LogWrite(TimeDate + "mob hit");

    timer2.Stop();

    timer1.Tick += new EventHandler(timer1_Tick);
    timer1.Interval = (1000);
    timer1.Enabled = true;
    timer1.Start();

}
4

2 に答える 2

1

これは@Epsil0neRが意味するものだと確信しています...

public partial class Form1 : Form
{

    public Form1()
    {
        InitializeComponent();

        timer1.Tick += new EventHandler(timer1_Tick);
        timer1.Interval = (1000);
        timer1.Enabled = false;

        timer2.Tick += new EventHandler(timer2_Tick);
        timer2.Interval = (1000);
        timer2.Enabled = false;
    }

    private void buttonStart_Click(object sender, EventArgs e)
    {
        buttonStart.Enabled = false;
        buttonStop.Enabled = true;

        timer1.Start();
    }

    private void buttonStop_Click(object sender, EventArgs e)
    {
        timer1.Stop();
        timer2.Stop();

        buttonStart.Enabled = true;
        buttonStop.Enabled = false;
    }

    private void LogWrite(string txt)
    {
        textBoxCombatLog.AppendText(txt + Environment.NewLine);
        textBoxCombatLog.SelectionStart = textBoxCombatLog.Text.Length;
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        timer1.Stop();

        LogWrite(TimeDate + "player hit");

        timer2.Start();
    }

    private void timer2_Tick(object sender, EventArgs e)
    {
        timer2.Stop();

        LogWrite(TimeDate + "mob hit");

        timer1.Start();
    }

    private string TimeDate
    {
        get { return DateTime.Now.ToString("HH:mm:ss") + ": "; }
    }

}
于 2013-05-23T20:23:14.973 に答える