폼에 레이블을 가져와서 넣어주고 레이블을 크기를 만져주기위해 레이아웃의 AutoSize - False로 지정해주고 크기를 맘에 들게 지정. + 이름은 lblTime으로 바꾸어줌
private void Form1_Load(object sender, EventArgs e)
{
lblTime.Location = new Point(
(ClientSize.Width / 2 - lblTime.Width / 2), (ClientSize.Height / 2 - lblTime.Height / 2));
lblTime.Font = new Font("맑은고딕", 30, FontStyle.Bold);
lblTime.Text = "";
timer1.Interval = 1000;
timer1.Tick += Timer1_Tick;
timer1.Start();
}
lblTime레이블의 위치를 지정해주고 폰트 및 시간관련하여 값을 지정해주는 것이다.
Location , Point를 이용해 정확히 폼의 중간에 지정해준다.
timer1.interval은 1000으로 지정해주면 1초로 지정된다.
timer1.Tick += Timer1_Tick; 계속 timer1에 값을 전달
private void Timer1_Tick(object sender, EventArgs e)
{
lblTime.Text = DateTime.Now.ToString(); //DateTime(구조체)
}
DataTime함수를 이용해 lblTime에 현재시각을 1초마다 업데이트를 한다.
'C#' 카테고리의 다른 글
031_WPFHELLO (0) | 2022.04.12 |
---|---|
029_DateTimePicker (0) | 2022.04.06 |
027_ComboBox를 이용한 성적계산기 (0) | 2022.04.06 |
026_ComboBox (0) | 2022.04.06 |
025_ListBox (0) | 2022.04.06 |