您的位置:首页 > 编程语言 > C#

c#简单屏幕保护程序,共4个线程

2015-03-31 15:43 441 查看
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Threading;

using System.Runtime.InteropServices;

namespace WindPingBao02

{

    public partial class Form1 : Form   //共4个线程

    {

        int temp,dx,dy;

        [DllImport("user32.dll", EntryPoint = "ShowCursor", CharSet = CharSet.Auto)]

        public extern static void ShowCursor(int status); //声明函数(显示鼠标)

        public Form1()

        {

            InitializeComponent();

            temp = 0;

            dx = Control.MousePosition.X;

            dy = Control.MousePosition.Y;

            ShowCursor(0);//隐藏鼠标

            this.timer1.Enabled = true;//开始计时

            //Thread.Sleep(1000);

            this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);//添加鼠标移动事件

        }

        private void timer1_Tick(object sender, EventArgs e)

        {

            if (temp == 0) 

                this.label1.Location = new Point(label1.Location.X -400,label1.Location.Y+300);

            else if(temp == 1)

                this.label1.Location = new Point(label1.Location.X + 400, label1.Location.Y + 300);

            else if (temp == 2)

                this.label1.Location = new Point(label1.Location.X + 400, label1.Location.Y - 300);

            else if (temp == 3)

                this.label1.Location = new Point(label1.Location.X - 400, label1.Location.Y - 300);

            if ((temp == 3)) temp = 0;

            else temp++;

        }

        //加以判断,减少灵敏度。XY移动均大于20才执行

        private void Form1_MouseMove(object sender, MouseEventArgs e)

        {

            if ((Control.MousePosition.X - dx > 20 || dx - Control.MousePosition.X > 20) &&

                (Control.MousePosition.Y - dy > 20 || dy - Control.MousePosition.Y > 20))

            {

                ShowCursor(1);

                this.Close();

            }

        }

        private void Form1_KeyPress(object sender, KeyPressEventArgs e)

        {

            ShowCursor(1);

            this.Close();

        }

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息