当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 用C#写的一个简单屏幕保护程序

ASP.NET
asp.net ajax功能强大的UpdatePanel控件
mscorwks.dll在.Net中的地位及代码保护应用
使用.NET实现你的IP切换器
在ADO.NET中用参数化查询缩短开发时间
Login控件:用户登录失败的消息提示
如何用C#来部署数据库
.net打包自动安装数据库
数据库开发个人总结(ADO.NET小结)
ASP.NET如何进行性能优化问题(2)
ASP.NET如何进行性能优化问题(1)
用.Net实现基于CSS的AJAX开发(6)
用.Net实现基于CSS的AJAX开发(5)
用.Net实现基于CSS的AJAX开发(4)
用.Net实现基于CSS的AJAX开发(3)
用.Net实现基于CSS的AJAX开发(2)
用.Net实现基于CSS的AJAX开发(1)
C#下用P2P技术实现点对点聊天
ASP.NET服务器端异步Web方法
在asp.net中如何从视频文件中抓取一桢并生成图像文件
.NET中多线程的同步资源访问

ASP.NET 中的 用C#写的一个简单屏幕保护程序


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 27 ::
收藏到网摘: n/a

ScreenSaver.cs

using System;
using System.Windows.Forms;

namespace ScreenSaver
{
 public class DotNETScreenSaver
 {
  [STAThread]
  static void Main(string[] args)
  {
   if (args.Length > 0)
   {
    if (args[0].ToLower().Trim().Substring(0,2) == "/c")
    {
     MessageBox.Show("This Screen Saver has no options you can set.", ".NET Screen Saver", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
    }
    else if (args[0].ToLower() == "/s")
    {
     for (int i = Screen.AllScreens.GetLowerBound(0); i <= Screen.AllScreens.GetUpperBound(0); i++)
      System.Windows.Forms.Application.Run(new ScreenSaverForm(i));   
    }
   }
   else
   {
    for (int i = Screen.AllScreens.GetLowerBound(0); i <= Screen.AllScreens.GetUpperBound(0); i++)
     System.Windows.Forms.Application.Run(new ScreenSaverForm(i));   
   }
  }
 }
}


ScreenSaverForm.cs

using System;
using System.Drawing;
using System.Windows.Forms;

namespace ScreenSaver
{
 public class ScreenSaverForm : System.Windows.Forms.Form
 {
  private Point MouseXY;
  private int ScreenNumber;

  public ScreenSaverForm(int scrn)
  {
   InitializeComponent();
   ScreenNumber = scrn;
  }
    private void ScreenSaverForm_Load(object sender, System.EventArgs e)
  {
   this.Bounds = Screen.AllScreens[ScreenNumber].Bounds;
   Cursor.Hide();
   TopMost = true;
  }

  private void OnMouseEvent(object sender, System.Windows.Forms.MouseEventArgs e)
  {
   if (!MouseXY.IsEmpty)
   {
    if (MouseXY != new Point(e.X, e.Y))
     Close();
    if (e.Clicks > 0)
     Close();
   }
   MouseXY = new Point(e.X, e.Y);
  }
 
  private void ScreenSaverForm_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
  {
   Close();
  }

  #region Windows Form Designer generated code
  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  private void InitializeComponent()
  {
   //
   // ScreenSaverForm
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
   this.BackColor = System.Drawing.Color.Black;
   this.ClientSize = new System.Drawing.Size(292, 273);
   this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
   this.Name = "ScreenSaverForm";
   this.Text = "ScreenSaver";
   this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ScreenSaverForm_KeyDown);
   this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.OnMouseEvent);
   this.Load += new System.EventHandler(this.ScreenSaverForm_Load);
   this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.OnMouseEvent);

  }
  #endregion
 }
}