using System; using System.Drawing; using System.Windows.Forms; namespace KitchenTimerApp { public partial class KitchenTimer : Form { private Label timerLabel; private Button hourUpButton; private Button hourDownButton; private Button minuteUpButton; private Button minuteDownButton; private Button secondUpButton; private Button secondDownButton; private Button startButton; private Button pauseButton; private Button resetButton; private Timer timer; private int remainingTime; private int pausedTime; private bool isPaused; public KitchenTimer() { InitializeComponent(); } private void InitializeComponent() { this.timerLabel = new System.Windows.Forms.Label(); this.timer = new System.Windows.Forms.Timer(); this.SuspendLayout(); // timerLabel this.timerLabel.AutoSize = true; this.timerLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 36F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.timerLabel.Location = new System.Drawing.Point(80, 20); this.timerLabel.Name = "timerLabel"; this.timerLabel.Size = new System.Drawing.Size(180, 55); this.timerLabel.TabIndex = 0; this.timerLabel.Text = "00:00"; // timer this.timer.Interval = 1000; this.timer.Tick += new System.EventHandler(this.timer_Tick); // KitchenTimer this.ClientSize = new System.Drawing.Size(334, 161); this.Controls.Add(this.timerLabel); this.Name = "KitchenTimer"; this.Text = "Kitchen Timer"; this.ResumeLayout(false); this.PerformLayout(); // Add additional controls and event handlers here hourUpButton = new Button(); hourUpButton.Text = "+"; hourUpButton.Location = new Point(25, 50); hourUpButton.Size = new Size(30, 30); hourUpButton.Click += new EventHandler(hourUpButton_Click); hourDownButton = new Button(); hourDownButton.Text = "-"; hourDownButton.Location = new Point(60, 50); hourDownButton.Size = new Size(30, 30); hourDownButton.Click += new EventHandler(hourDownButton_Click); minuteUpButton = new Button(); minuteUpButton.Text = "+"; minuteUpButton.Location = new Point(100, 50); minuteUpButton.Size = new Size(30, 30); minuteUpButton.Click += new EventHandler(minuteUpButton_Click); minuteDownButton = new Button(); minuteDownButton.Text = "-"; minuteDownButton.Location = new Point(135, 50); minuteDownButton.Size = new Size(30, 30); minuteDownButton.Click += new EventHandler(minuteDownButton_Click); secondUpButton = new Button(); secondUpButton.Text = "+"; secondUpButton.Location = new Point(175, 50); secondUpButton.Size = new Size(30, 30); secondUpButton.Click += new EventHandler(secondUpButton_Click); secondDownButton = new Button(); secondDownButton.Text = "-"; secondDownButton.Location = new Point(210, 50); secondDownButton.Size = new Size(30, 30); secondDownButton.Click += new EventHandler(secondDownButton_Click); startButton = new Button(); startButton.Text = "Start"; startButton.Location = new Point(25, 100); startButton.Size = new Size(75, 30); startButton.Click += new EventHandler(startButton_Click); pauseButton = new Button(); pauseButton.Text = "Pause"; pauseButton.Location = new Point(110, 100); pauseButton.Size = new Size(75, 30); pauseButton.Click += new EventHandler(pauseButton_Click); resetButton = new Button(); resetButton.Text = "Reset"; resetButton.Location = new Point(195, 100); resetButton.Size = new Size(75, 30); resetButton.Click += new EventHandler(resetButton_Click); Controls.Add(timerLabel); Controls.Add(hourUpButton); Controls.Add(hourDownButton); Controls.Add(minuteUpButton); Controls.Add(minuteDownButton); Controls.Add(secondUpButton); Controls.Add(secondDownButton); Controls.Add(startButton); Controls.Add(pauseButton); Controls.Add(resetButton); } private void timer_Tick(object sender, EventArgs e) { remainingTime--; if (remainingTime < 0) { timer.Stop(); MessageBox.Show("タイマーが終了しました。"); } else { int hours = remainingTime / 3600; int minutes = (remainingTime % 3600) / 60; int seconds = remainingTime % 60; timerLabel.Text = hours.ToString("D2") + ":" + minutes.ToString("D2") + ":" + seconds.ToString("D2"); } } private void hourUpButton_Click(object sender, EventArgs e) { remainingTime += 3600; UpdateTimerLabel(); } private void hourDownButton_Click(object sender, EventArgs e) { if (remainingTime >= 3600) { remainingTime -= 3600; UpdateTimerLabel(); } } private void minuteUpButton_Click(object sender, EventArgs e) { remainingTime += 60; UpdateTimerLabel(); } private void minuteDownButton_Click(object sender, EventArgs e) { if (remainingTime >= 60) { remainingTime -= 60; UpdateTimerLabel(); } } private void secondUpButton_Click(object sender, EventArgs e) { remainingTime += 1; UpdateTimerLabel(); } private void secondDownButton_Click(object sender, EventArgs e) { if (remainingTime >= 1) { remainingTime -= 1; UpdateTimerLabel(); } } private void startButton_Click(object sender, EventArgs e) { timer.Start(); isPaused = false; } private void pauseButton_Click(object sender, EventArgs e) { if (!isPaused) { timer.Stop(); pausedTime = remainingTime; isPaused = true; } else { remainingTime = pausedTime; UpdateTimerLabel(); timer.Start(); isPaused = false; } } private void resetButton_Click(object sender, EventArgs e) { timer.Stop(); remainingTime = 0; UpdateTimerLabel(); } private void UpdateTimerLabel() { int hours = remainingTime / 3600; int minutes = (remainingTime % 3600) / 60; int seconds = remainingTime % 60; timerLabel.Text = hours.ToString("D2") + ":" + minutes.ToString("D2") + ":" + seconds.ToString("D2"); } [STAThread] static void Main() { Application.Run(new KitchenTimer()); } } }