Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Diagnostics; //Stopwatch 클래스 이용 위함
  11.  
  12. namespace stopwatch_2
  13. {
  14. public partial class stopwatch_2 : Form
  15. {
  16. public stopwatch_2()
  17. {
  18. InitializeComponent();
  19. }
  20.  
  21. //스톱워치 클래스를 이용하여 인스턴스 생성
  22. Stopwatch stopWatch = new Stopwatch();
  23.  
  24. private void myTimer_Tick(object sender, EventArgs e)
  25. {
  26. //흐른 시간은 지금 현재 시각 - 시작 시각
  27. TimeSpan flowTime = stopWatch.Elapsed;
  28.  
  29. //흐른 시간 출력
  30. lblTime.Text = String.Format("{0:00}:{1:00}:{2:00}", flowTime.Hours, flowTime.Minutes, flowTime.Seconds);
  31. }
  32.  
  33. private void btnStatus_Click(object sender, EventArgs e)
  34. {
  35. //시작 버튼일 경우, 중지 버튼으로 변경
  36. if (btnStatus.Text == "시작")
  37. {
  38. btnStatus.Text = "중지";
  39.  
  40. //스톱워치 시작
  41. stopWatch.Start();
  42. }
  43.  
  44. //중지 버튼일 경우, 시작 버튼으로 변경
  45. else
  46. {
  47. btnStatus.Text = "시작";
  48. stopWatch.Stop();
  49. }
  50.  
  51. //타이머 활성화, 비활성화
  52. myTimer.Enabled = !myTimer.Enabled;
  53. }
  54.  
  55. private void btnExit_Click(object sender, EventArgs e)
  56. {
  57. //나가기
  58. this.Close();
  59. }
  60.  
  61. private void btnReset_Click(object sender, EventArgs e)
  62. {
  63. //중지한 상태에서 초기화 버튼을 눌렀을 경우
  64. if (btnStatus.Text == "시작")
  65. {
  66. stopWatch.Reset();
  67. lblTime.Text = "00:00:00";
  68. }
  69. //초를 재던 중 초기화 버튼을 눌렀을 경우
  70. else
  71. {
  72. stopWatch.Restart();
  73. btnStatus.Text = "중지";
  74. }
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement