using System; using System.ComponentModel; using System.Drawing; using System.Threading; using System.Windows.Forms; namespace UAS_AutoPass { public partial class Tip : Form { int state; public Tip() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { this.ShowInTaskbar = false; this.Left = Screen.PrimaryScreen.WorkingArea.Width - this.Width; this.Top = this.Height; state = 0; label1.Text = DateTime.Now.ToString(); } public void startthread(string filename,string type) { label1.Text = filename; if(type == "OK") label1.ForeColor = System.Drawing.Color.Green; if(type == "NG") label1.ForeColor = System.Drawing.Color.Red; //thread.Start(); using (BackgroundWorker bw = new BackgroundWorker()) { bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted); bw.DoWork += new DoWorkEventHandler(bw_DoWork); bw.RunWorkerAsync("Tank"); } } private void bw_DoWork(object sender, DoWorkEventArgs e) { } private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (checkBox1.Checked) { aa(); Thread.Sleep(2000); bb(); } } public void aa() { if (state == 0) { state = 1; int t = this.Left; for (int i = t; i >= Screen.PrimaryScreen.WorkingArea.Width - this.Width; i--) { this.Left = i; Application.DoEvents(); } state = 0; } } public void bb() { if (this.Left <= Screen.PrimaryScreen.WorkingArea.Width - 10 && state == 0) { state = 1; int t = this.Left; for (int i = t; i < Screen.PrimaryScreen.WorkingArea.Width - 10; i++) { this.Left = i; Application.DoEvents(); } state = 0; } } private void Form2_MouseEnter(object sender, EventArgs e) { if (state == 0) { state = 1; int t = this.Left; for (int i = t; i >= Screen.PrimaryScreen.WorkingArea.Width - this.Width; i=i-2) { this.Left = i; Application.DoEvents(); } state = 0; } } private void Form2_MouseLeave(object sender, EventArgs e) { if (checkBox1.Checked) { Panel p = sender as Panel; //如果Mouse Leave,则清除背景图,否则不处理 Point mousePoint = p.PointToClient(Control.MousePosition); if (!p.ClientRectangle.Contains(mousePoint)) { if (this.Left <= Screen.PrimaryScreen.WorkingArea.Width - 10 && state == 0) { state = 1; int t = this.Left; for (int i = t; i < Screen.PrimaryScreen.WorkingArea.Width - 10; i = i + 2) { this.Left = i; Application.DoEvents(); } state = 0; } } } } private void panel1_Paint(object sender, PaintEventArgs e) { } private void checkBox1_CheckedChanged(object sender, EventArgs e) { if (!checkBox1.Checked) aa(); } } }