当前位置:首页 > 网络编程 > WEB编程 > ASP.net > 用C#做ScreenSaver

用C#做ScreenSaver

点击次数:20 次 发布日期:2008-11-26 23:11:29 作者:源代码网
源代码网推荐
源代码网推荐/* 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;
源代码网推荐using System.Drawing;
源代码网推荐using System.Collections;
源代码网推荐using System.ComponentModel;
源代码网推荐using System.WinForms;
源代码网推荐using System.Data;
源代码网推荐
源代码网推荐
源代码网推荐/// <summary>
源代码网推荐/// Summary description for Form1.
源代码网推荐/// </summary>
源代码网推荐public class ScreenSaver : System.WinForms.Form
源代码网推荐{
源代码网推荐/// <summary>
源代码网推荐/// Required designer variable.
源代码网推荐/// </summary>
源代码网推荐private System.ComponentModel.Container components;
源代码网推荐private System.WinForms.Timer timerSaver;
源代码网推荐private System.WinForms.Label lblMarquee;
源代码网推荐
源代码网推荐private int iSpeed = 2;
源代码网推荐private string strMarqueeText="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()
源代码网推荐{
源代码网推荐InitializeComponent();
源代码网推荐
源代码网推荐lblMarquee.Font=fontMarquee;
源代码网推荐lblMarquee.ForeColor=colorMarquee;
源代码网推荐System.Drawing.Cursor.Hide();
源代码网推荐}
源代码网推荐
源代码网推荐/// <summary>
源代码网推荐/// Clean up any resources being used.
源代码网推荐/// </summary>
源代码网推荐public override void Dispose()
源代码网推荐{
源代码网推荐base.Dispose();
源代码网推荐components.Dispose();
源代码网推荐}
源代码网推荐
源代码网推荐/// <summary>
源代码网推荐/// Required method for Designer support - do not modify
源代码网推荐/// the contents of this method with the code editor.
源代码网推荐/// </summary>
源代码网推荐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;
源代码网推荐this.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;
源代码网推荐this.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;
源代码网推荐lblMarquee.Height=lblMarquee.Font.Height;
源代码网推荐lblMarquee.Width=lblMarquee.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.
源代码网推荐lblMarquee.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.Y == 0)
源代码网推荐lblMarquee.Location=new System.Drawing.Point(lblMarquee.Location.X,
源代码网推荐(ssWorkArea.Height / 2));
源代码网推荐
源代码网推荐// If label is in the middle of the screen move it to the bottom.
源代码网推荐else if(lblMarquee.Location.Y== ssWorkArea.Height /2)
源代码网推荐lblMarquee.Location=new System.Drawing.Point(lblMarquee.Location.X,ssWorkArea.Height -
源代码网推荐lblMarquee.Height);
源代码网推荐//Move the label back to the top.
源代码网推荐else
源代码网推荐lblMarquee.Location=new System.Drawing.Point(lblMarquee.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 = e.X;
源代码网推荐iyStart = e.Y;
源代码网推荐return;
源代码网推荐}
源代码网推荐// Has the mouse cursor moved since the screen saver was started?
源代码网推荐else if (e.X != ixStart || e.Y != 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();
源代码网推荐}
源代码网推荐
源代码网推荐/// <summary>
源代码网推荐/// The main entry point for the application.
源代码网推荐/// </summary>
源代码网推荐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.IconInformation);
源代码网推荐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());
源代码网推荐}
源代码网推荐
源代码网推荐}
源代码网推荐}
源代码网推荐
源代码网推荐
源代码网推荐
源代码网推荐
源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华