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