void MyTimer_FormClosed(object sender, FormClosedEventArgs e) { MyTimer = null; }
private void btnCreateTimer_Click(object sender, EventArgs e) { using (var dialog = new frmCreateTimer()) { if (dialog.ShowDialog() == DialogResult.OK) { var timer = new frmTimer(dialog.TimerName, dialog.TimerDuration); if (dialog.DockTimer) timer.MdiParent = this; timer.Show(); } } }
private void btnTimer_Click(object sender, EventArgs e) { if (MyTimer == null) { // It's possible the timer was opened previously. Go look for it. foreach (Form form in this.MdiParent.MdiChildren) { if (form is frmTimer) { frmTimer timer = (frmTimer)form; if (timer.Text == "Timer: " + ThisRound.TournamentName + " -- Time Remaining") { MyTimer = timer; MyTimer.WindowState = FormWindowState.Normal; MyTimer.Focus(); return; } } } MyTimer = new frmTimer(ThisRound.TournamentName + " -- Time Remaining", ThisRound.Length); MyTimer.FormClosed += MyTimer_FormClosed; MyTimer.Show(); } else { MyTimer.WindowState = FormWindowState.Normal; MyTimer.Focus(); } }