MainForm.cs 859 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using KeepScreenLight.Utils;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace KeepScreenLight
  12. {
  13. public partial class MainForm : Form
  14. {
  15. bool flag = false;
  16. public MainForm()
  17. {
  18. InitializeComponent();
  19. }
  20. private void button1_Click(object sender, EventArgs e)
  21. {
  22. if (!flag)
  23. {
  24. // 让屏幕常亮
  25. SystemSleep.PreventForCurrentThread();
  26. button1.Text = "Stop";
  27. }
  28. else
  29. {
  30. SystemSleep.RestoreForCurrentThread();
  31. button1.Text = "Start";
  32. }
  33. }
  34. }
  35. }