C#/WindowForm
Timer 사용
hyun0229
2022. 4. 6. 11:17
실행코드
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 _29
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
label1.Location = new Point(ClientSize.Width / 2 - label1.Width /
2,ClientSize.Height / 2 - label1.Height / 2);
label1.Font = new Font("휴먼굴림체", 30, FontStyle.Bold);
label1.ForeColor = Color.Blue;
label1.Text = "";
timer1.Interval = 1000;
timer1.Tick += Timer1_Tick;
timer1.Start();
}
private void Timer1_Tick(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToString();
label1.Location = new Point(ClientSize.Width / 2 - label1.Width
/ 2,ClientSize.Height / 2 - label1.Height / 2);
}
}
}