/ * Program: a Simple Screen Saver
* File name: Screensaver.cs
* Author: Tran Khanh Hien
* Date: 06/20/2001
* email: hientk@yahoo.com
* /
Namespace screen_saver {using system.drawing; using system.collections; using system.componentmodel; using system.winforms; using system.data ;. using system.data ;. USING SYSTEM.
///
Private int ispeed = 2; private string strmarQuetext = "c sharp screen saver";
private System.Drawing.Font fontMarquee = new System.Drawing.Font ( "Arial", 20, System.Drawing.FontStyle.Bold); private Color colorMarquee = System.Drawing.Color.FromARGB (255,255,255);
Private int idistance; private int ixstart = 0; private INT IYSTART = 0;
Public screensaver () {initializationComponent ();
LBLMARQUEE.FONT = fontmarque; lblmarquee.forecolor = colorquee; system.drawing.cursor.hide ();}
///
///
new System.WinForms.MouseEventHandler (this.Form1_MouseDown); this.MouseMove = new System.WinForms.MouseEventHandler (this.Form1_MouseMove); this.Controls.Add (this.lblMarquee);} protected void timerSaver_Tick (object sender, System. Eventargs e) {lblmarqueE.text = strmarqueEtext; lblmarque.height = lblmarque.Font.Height; lblmarque.width = lblmarque.text.length * (int) lblmarquee.font.size;
Playscreensaver ();
Private void Playscreensaver () {/ get the working area of the the computer screen.system.drawing.Rectangle Ssworkarea = system.winforms.screen.getworkingarea (this);
LBLMARQUEE.LOCATION = new system.drawing.point (Ssworkarea.width - iDistance, lblmarquee.location.y);
// make the label visible if it is not currently visible.lblmarque.visible = true;
// Increment the label distance based on the speed set by the user.iDistance = iSpeed; // If the label is offscreen, then we want to reposition it to the right.if (lblMarquee.Location.X <= - (lblMarquee .Width)) {// reset the distance to 0.idistance = 0;
// if the label is at the top, move it to the middle.if (lblmarquee.location.l == 0) lblmarquee.location = new system.drawing.point (lblmarque.location.x, (ssworkarea.height / 2) ));
// if label is in the middle of the screen move ing (lblmarque.location.y == ssworkarea.height /2 )lmarque.location=new system.drawing.point (lblmarque.location.x, SSWORKAREA.HEIGHT - LBLMARQUE.HEIGHT); //move the label back to the top.elselblmarque.location = new system.drawing.point (lblmarque.location.x, 0);}}
Protected Void Form1_MouseDown (Object Sender, System.winForms.MouseEventArgs E) {stopscreensaver ();
protected void Form1_MouseMove (object sender, System.WinForms.MouseEventArgs e) {// Determine if the mouse cursor position has been stored previously.if (ixStart == 0 && iyStart == 0) {// Store the mouse cursor coordinates.ixStart = EX; IYSTART = EY; RETURN;} // HAS THE MOUSE CURSOR MOVED SINCE The Screen Saver WASS STARTED? ELSE IF (EX! = IXStart || EY! = iYstart) stopscreensaver ();}
Private void stopscreensaver () {system.drawing.cursor.show (); Timersaver.enabled = false; application.exit ();
Protected void form1_keydown (object sender, system.winforms.keyeventargs e) {stopscreensaver ();
///
// diaplay the password dialog else if (args [0] == "/ a") {MessageBox.show ("Passwords Are Not Available for this Screen Saver", "C # Screen Saver", MessageBox.iconInformation; Application.exit ();}} // for any other args -> start.else application.run (new screensaver ());}
}