Form2.cs 4.0 KB

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