A simple screen saver written in C #

Source: Internet
Author: User
Program 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 for 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 to Designer support-do not modify
The contents is 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
}
}




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.