C# Windows フォームアプリケーションのtextboxに現在の時刻を表示する


スポンサーリンク

C#のお勉強。

作ったのは、テキストボックスの中に現在の時刻を表示して、1秒ごとに更新していくもの。

f:id:sho322:20150130123219j:plain

ソースコードは以下のとおりです。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Timer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            textBoxDate.Text = DateTime.Now.ToString(("dddd" + ("," + "yyyy-MM-dd")));
            timer1.Interval = 1000;
            timer1.Enabled = true;

        }

        private void Form1_HelpRequested(object sender, HelpEventArgs hlpevent)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            textBox1.Text = DateTime.Now.ToString("HH:mm:ss");
        }
    }
}