用C#写的一个简单屏幕保护程序
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
}
}
相关文章:
- · 在C#中使用异步Socket编程实现TCP网络服务的C/S的通讯构架(一)----基础类库部分
- · c#.net常用的小函数和方法集
- · RC2加密算法在C#的应用----完善版
- · 简单的c#文本文件读写
- · c#.net常用的小函数和方法集
- · 用Visual C#打造个性化的IE浏览器
- · 如何用UltraEdit编译C#源程序
- · .Net/C#: 实现支持断点续传多线程下载的 Http Web 客户端工具类 (C# DIY HttpWebClient)
- · Visual C#网络编程之TCP
- · C# Programming Guidelines
- · C#设计模式之原型(ProtoType)
- · C#设计模式之抽象工厂(AbstractFactory)
- · C# Coding Standard
- · c#.net常用的小函数和方法集
- · c#.net函数列表.txt
- · c#.net常用的小函数参考
- · C#中使用XML——编写XML
- · C#版ftp方法实现类库代码
- · Visual C# .NET 入门
- · 在C#后代码里使用IE WEB Control TreeView
- · C#里操作时间的例子!
- · 在C#中利用SharpZipLib进行文件的压缩和解压缩
- · C#中使用XML——基于DOM的案例分析
- · 远程重启计算机(C#)
- · C#中使用XML——实现DOM
- · C#中使用XML——编写XML
- · 用C#实现生成PDF文档
- · 使用C#编写的一个定时关机程序
- · 三层架构之数据库访问层完全篇(C#)
- · c#中使用 Win32 和其他库
- · C#执行存储过程的简化
- · 用C#写一个Web自定义控件
- · 在C#中用最简洁有效的代码执行存储过程并返回数据
- · C#里的InputBox
- · 关于C#数组初始化的效率测试
- · C#第2个程序,读取偶网站的数据!
- · 深入理解C#编程中的组件-事件-委托
- · 通过Visual C#.NET建一个DTS任务
