Form1.cs 990 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. namespace WindowsFormsTimer
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18. private void Form1_Load(object sender, EventArgs e)
  19. {
  20. timer1.Interval = 1000;
  21. }
  22. private void timer1_Tick(object sender, EventArgs e)
  23. {
  24. textBox1.Text = DateTime.Now.ToString();
  25. }
  26. private void button1_Click(object sender, EventArgs e)
  27. {
  28. if (button1.Text == "开始")
  29. {
  30. timer1.Enabled = true;
  31. button1.Text = "停止";
  32. }
  33. else
  34. {
  35. timer1.Enabled = false;
  36. button1.Text = "开始";
  37. }
  38. }
  39. }
  40. }