Form2.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using System;
  2. using System.ComponentModel;
  3. using System.Drawing;
  4. using System.Threading;
  5. using System.Windows.Forms;
  6. namespace UAS_AutoPass
  7. {
  8. public partial class Tip : Form
  9. {
  10. int state;
  11. public Tip()
  12. {
  13. InitializeComponent();
  14. }
  15. private void Form2_Load(object sender, EventArgs e)
  16. {
  17. this.ShowInTaskbar = false;
  18. this.Left = Screen.PrimaryScreen.WorkingArea.Width - this.Width;
  19. this.Top = this.Height;
  20. state = 0;
  21. label1.Text = DateTime.Now.ToString();
  22. }
  23. public void startthread(string filename,string type)
  24. {
  25. label1.Text = filename;
  26. if(type == "OK")
  27. label1.ForeColor = System.Drawing.Color.Green;
  28. if(type == "NG")
  29. label1.ForeColor = System.Drawing.Color.Red;
  30. //thread.Start();
  31. using (BackgroundWorker bw = new BackgroundWorker())
  32. {
  33. bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
  34. bw.DoWork += new DoWorkEventHandler(bw_DoWork);
  35. bw.RunWorkerAsync("Tank");
  36. }
  37. }
  38. private void bw_DoWork(object sender, DoWorkEventArgs e)
  39. {
  40. }
  41. private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
  42. {
  43. if (checkBox1.Checked)
  44. {
  45. aa();
  46. Thread.Sleep(2000);
  47. bb();
  48. }
  49. }
  50. public void aa()
  51. {
  52. if (state == 0)
  53. {
  54. state = 1;
  55. int t = this.Left;
  56. for (int i = t; i >= Screen.PrimaryScreen.WorkingArea.Width - this.Width; i--)
  57. {
  58. this.Left = i;
  59. Application.DoEvents();
  60. }
  61. state = 0;
  62. }
  63. }
  64. public void bb()
  65. {
  66. if (this.Left <= Screen.PrimaryScreen.WorkingArea.Width - 10 && state == 0)
  67. {
  68. state = 1;
  69. int t = this.Left;
  70. for (int i = t; i < Screen.PrimaryScreen.WorkingArea.Width - 10; i++)
  71. {
  72. this.Left = i;
  73. Application.DoEvents();
  74. }
  75. state = 0;
  76. }
  77. }
  78. private void Form2_MouseEnter(object sender, EventArgs e)
  79. {
  80. if (state == 0)
  81. {
  82. state = 1;
  83. int t = this.Left;
  84. for (int i = t; i >= Screen.PrimaryScreen.WorkingArea.Width - this.Width; i=i-2)
  85. {
  86. this.Left = i;
  87. Application.DoEvents();
  88. }
  89. state = 0;
  90. }
  91. }
  92. private void Form2_MouseLeave(object sender, EventArgs e)
  93. {
  94. if (checkBox1.Checked)
  95. {
  96. Panel p = sender as Panel;
  97. //如果Mouse Leave,则清除背景图,否则不处理
  98. Point mousePoint = p.PointToClient(Control.MousePosition);
  99. if (!p.ClientRectangle.Contains(mousePoint))
  100. {
  101. if (this.Left <= Screen.PrimaryScreen.WorkingArea.Width - 10 && state == 0)
  102. {
  103. state = 1;
  104. int t = this.Left;
  105. for (int i = t; i < Screen.PrimaryScreen.WorkingArea.Width - 10; i = i + 2)
  106. {
  107. this.Left = i;
  108. Application.DoEvents();
  109. }
  110. state = 0;
  111. }
  112. }
  113. }
  114. }
  115. private void panel1_Paint(object sender, PaintEventArgs e)
  116. {
  117. }
  118. private void checkBox1_CheckedChanged(object sender, EventArgs e)
  119. {
  120. if (!checkBox1.Checked)
  121. aa();
  122. }
  123. }
  124. }