All pastes #637656 Raw Edit

Miscellany

public text v1 · immutable
#637656 ·published 2007-07-29 03:03 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace StreetGlowScreenSaver
{
    public partial class Form1 : Form
    {
        //Various variables we will be using.
        public int mouseX, mouseY, ScreenHeight, ScreenWidth, logoVelocityX, logoVelocityY;
        
        //Random we will use to decide how fast the image moves.
        public Random ran;

        //Get the current running directory

        private System.Resources.ResourceManager rm = new System.Resources.ResourceManager("Form1", System.Reflection.Assembly.GetExecutingAssembly());
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            // Here we are simply setting up some properties for the form.
            Logo.Image = (Image)rm.GetObject("logo");
            //Gets the position of the current mouse position so we can later check if it's been moved
            mouseX = MousePosition.X;
            mouseY = MousePosition.Y;

            //Loading and assigning the variables to store the users screen resolution
            ScreenHeight = Screen.PrimaryScreen.Bounds.Height;
            ScreenWidth = Screen.PrimaryScreen.Bounds.Width;

            //Set the windows width and height to the resolution of the desktop
            this.Width = Screen.PrimaryScreen.WorkingArea.Width;
            this.Height = Screen.PrimaryScreen.WorkingArea.Height;
            this.TopMost = true;

            //Move the window to the top left of the screen.
            this.Top = 0;
            this.Left = 0;

            //Set the label to show http://www.streetglow.com and display at the bottom of the screen
            //In the center

            //websiteURL.Text = @"Made by exodus from http://www.streetglow.com";
            websiteURL.Text = "";
            websiteURL.Left = ScreenWidth / 2 - (websiteURL.Width / 2);
            websiteURL.Top = Screen.PrimaryScreen.Bounds.Bottom - websiteURL.Height;
            

            //Hide the Cursor
            Cursor.Hide();

            //Load the image into the pictureBox and assign the properties.
            Logo.Width = 280;
            Logo.Height = 68;

            Logo.Top = ScreenHeight / 2 - (Logo.Height / 2);
            Logo.Left = ScreenWidth / 2 - (Logo.Width / 2);
            
            //Make the background color of the for black.
            this.BackColor = Color.Black;

            //Set the speed at which the image moves. (Sets randomly betwen 2 and 7)
            if (Settings.Default.customSpeed == false)
            {
                ran = new Random();
                logoVelocityX = ran.Next(2, 8);
                logoVelocityY = ran.Next(2, 8);
            }
            else
            {
                logoVelocityX = Settings.Default.speedX;
                logoVelocityY = Settings.Default.speedY;
            }
        }

        private void updateTimer_Tick(object sender, EventArgs e)
        {
            if (checkMouseMovement())
            {
                this.Close();
            }
        }

        private void updateDraw_Tick(object sender, EventArgs e)
        {
            Draw();
        }

        private bool checkMouseMovement()
        {
            if (mouseX != MousePosition.X)
            {
                return true;
            }
            if (mouseY != MousePosition.Y)
            {
                return true;
            }

            return false;
        }

        private void Draw()
        {
            CheckWallCollisions();
            MoveLogo();
        }

        private void MoveLogo()
        {
            Logo.Top += logoVelocityY;
            Logo.Left += logoVelocityX;
        }

        private void CheckWallCollisions()
        {
            if (Logo.Left < 0)
            {
                logoVelocityX *= -1;
            }
            else if (Logo.Left + Logo.Width > ScreenWidth)
            {
                logoVelocityX *= -1;
            }

            if (Logo.Top < 0)
            {
                logoVelocityY *= -1;
            }
            else if (Logo.Top + Logo.Height > ScreenHeight)
            {
                logoVelocityY *= -1;
            }
        }

    }
}