博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

C#写的最简单的屏幕保护程序

Posted on 2005-03-31 20:09    阅读(448)  评论(0编辑  收藏  举报

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

 

namespace ScanServer

{

     /// <summary>

     /// Form1 的摘要说明。

     /// </summary>

     public class Form1 : System.Windows.Forms.Form

     {

         /// <summary>

         /// 必需的设计器变量。

         /// </summary>

         private System.ComponentModel.Container components = null;

         private int time=0;

 

         public Form1()

         {

              //

              // Windows 窗体设计器支持所必需的

              //

              InitializeComponent();

              Cursor.Hide();

              //

              // TODO: InitializeComponent 调用后添加任何构造函数代码

              //

         }

 

         /// <summary>

         /// 清理所有正在使用的资源。

         /// </summary>

         protected override void Dispose( bool disposing )

         {

              if( disposing )

              {

                   if (components != null)

                   {

                       components.Dispose();

                   }

              }

              base.Dispose( disposing );

         }

 

         #region Windows 窗体设计器生成的代码

         /// <summary>

         /// 设计器支持所需的方法 - 不要使用代码编辑器修改

         /// 此方法的内容。

         /// </summary>

         private void InitializeComponent()

         {

              //

              // Form1

              //

              this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);

              this.BackColor = System.Drawing.SystemColors.ControlText;

              this.ClientSize = new System.Drawing.Size(292, 266);

              this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;

              this.Name = "Form1";

              this.Text = "Form1";

              this.TopMost = true;

              this.WindowState = System.Windows.Forms.FormWindowState.Maximized;

              this.MouseHover += new System.EventHandler(this.Form1_MouseHover);

              this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);

 

         }

         #endregion

 

         /// <summary>

         /// 应用程序的主入口点。

         /// </summary>

         [STAThread]

         static void Main()

         {

              Application.Run(new Form1());

         }

 

         private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)

         {

              if(time++>5)

                   this.Close();

         }

 

         private void Form1_MouseHover(object sender, System.EventArgs e)

         {

              time=0;

         }

     }

}