CountDownForm1
Form1.cs
using System;
using System.Windows.Forms;
namespace CountDown
{
public partial class Form1 : Form
{
private readonly DateTime OlympicOpeningCeremony = new DateTime(2020, 7, 24, 20, 00, 00);
private int count = 1;
private readonly Random random = new Random();
private int ran;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
labelCountDown.Text = "";
PictureClear();
}
private void Timer1_Tick(object sender, EventArgs e)
{
DateTime today = DateTime.Now;
TimeSpan difference = OlympicOpeningCeremony - today;
labelCountDown.Text =
difference.Days.ToString() + "日" +
difference.Hours.ToString("00") + "時" +
difference.Minutes.ToString("00") + "分" +
difference.Seconds.ToString("00") + "秒";
}
private void Timer2_Tick(object sender, EventArgs e)
{
PictureClear();
switch (count)
{
case 1:
pictureBox1.Visible = true;
break;
case 2:
pictureBox2.Visible = true;
break;
case 3:
pictureBox3.Visible = true;
break;
case 4:
pictureBox4.Visible = true;
break;
case 5:
pictureBox5.Visible = true;
break;
case 6:
pictureBox6.Visible = true;
break;
case 7:
ran = GetRandom();
if (ran == 7)
{
pictureBox7.Visible = true;
}
else if (ran == 8)
{
pictureBox8.Visible = true;
}
else if (ran == 9)
{
pictureBox9.Visible = true;
}
break;
case 8://表示時間を倍にするため
if (ran == 7)
{
pictureBox7.Visible = true;
}
else if (ran == 8)
{
pictureBox8.Visible = true;
}
else if (ran == 9)
{
pictureBox9.Visible = true;
}
break;
}
_ = count >= 8 ? count = 1 : count++;
}
public int GetRandom()
{
int ran = random.Next(7, 10);
return ran;
}
private void PictureClear()
{
pictureBox1.Visible = false;
pictureBox2.Visible = false;
pictureBox3.Visible = false;
pictureBox4.Visible = false;
pictureBox5.Visible = false;
pictureBox6.Visible = false;
pictureBox7.Visible = false;
pictureBox8.Visible = false;
pictureBox9.Visible = false;
}
}
}