Use C # to SCREENSAVER

xiaoxiao2021-03-06  71

/ * 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.

///

/// Summary description for form1./// public class screensaver: system.winforms.form {/// /// Required Designer variable./// Private system.componentmodel.container component; private system.winforms.timer Timersaver; Private system.winforms.label lblmarque;

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 ();}

///

/// clean up any resources being used./// public override void dispose () {base.dispose (); components.dispose ();

///

/// Required method for Designer support - do not modify /// the contents of this method with the code editor./// private void InitializeComponent () {System.Resources.ResourceManager resources = new System.Resources.ResourceManager (typeof (ScreenSaver)); this.components = new System.ComponentModel.Container (); this.timerSaver = new System.WinForms.Timer (this.components); this.lblMarquee = new System. WinForms.Label (); @ this.trayHeight = 90; @ this.trayLargeicon = false; @ this.trayautoarrange = true; @ Timersaver.SetLocation (new system.drawing.point (7, 7 )); timerSaver.Interval = 1; timerSaver.Enabled = true; timerSaver.Tick = new System.EventHandler (this.timerSaver_Tick); lblMarquee.Location = new System.Drawing.Point (88, 0); lblMarquee.Size = new System.Drawing.Size (128, 48); lblMarquee.ForeColor = System.Drawing.Color.White; lblMarquee.TabIndex = 0; lblMarquee.Visible = false; this.MaximizeBox = false; this.StartPosition = System.WinForms. FormstartPosition.manual; thi s.AutoScaleBaseSize = new System.Drawing.Size (5, 13); this.BorderStyle = System.WinForms.FormBorderStyle.None; this.KeyPreview = true; this.WindowState = System.WinForms.FormWindowState.Maximized; this.ShowInTaskbar = False; this.icon = (system.drawing.icon) Resources.getObject ("$ this.icon"); this.ControlBox = false; this.MinimizeBox = false; this.backcolor = system.drawing.color.black; tris .ClientSize = new system.drawing.size (300, 300); this.keydown = new system.winforms.keyeventhandler (this.form1_keydown); this.mousedown =

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 ();

///

////// public static void main (string [] args) {if (args.length == 1) {// Display the Options Dialog Box.if (Args [0]. Substring (0,2). Equals ("/ c")) {MessageBox.Show ("Options Are Not Available For this Screen Saver", "C # Screen Saver", MessageBox.iconInInformation Application.exit ();} // start the screen saver normally.else if (args [0] == "/ s)) Application.run (New ScreenSaver ());

// 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 ());}

}

转载请注明原文地址:https://www.9cbs.com/read-120153.html

New Post(0)