Shows how to create the screensavers and install in system

I just wanted to present an interesting topic to you today. Its about creating the screen savers in .net and tell you what, install the created screensaver in your machine in a simpler manner without requiring any software. To brief the steps its pretty simple in terms of the steps involved in creating the the screensaver and installing it in the machine.

Take a Windows Application of your choice, lets take C# for the demonstration purpose as the language for today.

 

Drag and drop a timer component (bearing id as timer1, the default one), ImageList component (with id as imgListScreen) onto the Designer of the visual studio.

 

Drag and drop two label controls (Can take any number  as you wish to, but for demonstration purpose I have taken couple of them (with lblMessage and lblMessage2 as ids).

Enter the text you desired to display in the label and make sure to increase the font of the lables atleast to 16.

 

Now, let see the code, which is pretty simple and self explainatory as well...

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

 

namespace ScreenSaverInCS

{

    public partial class Form1 : Form

    {

        public string navId = "";

           

        private int x = 10;

        private int y = 10;

        public Form1()

        {

            InitializeComponent();

        }

 

        private void timer1_Tick(object sender, EventArgs e)

        {

            lblMessage.Left += x;

            lblMessage2.Left += x;

            if ((lblMessage.Left >= this.Width - lblMessage.Width || lblMessage.Left < 0) || (lblMessage2.Left >= this.Width - lblMessage2.Width || lblMessage2.Left < 0))

            {

                x = x*(-1);

                Random rnd = new Random();

                //Random imgRnd = new Random();

                lblMessage.ForeColor = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255));

                lblMessage2.ForeColor = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255));

                //this.BackColor = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255));

                this.BackgroundImage = imgListScreen.Images[rnd.Next(3)];

 

            }

            lblMessage.Top += y;

            lblMessage2.Top += y;

            if ((lblMessage.Top >= this.Height - lblMessage.Height - 15 || lblMessage.Top < 0) || (lblMessage2.Top >= this.Height - lblMessage2.Height - 15 || lblMessage2.Top < 0))

            {

                y = y*(-1);

                Random rnd = new Random();

                //Random imgRnd = new Random();

                lblMessage.ForeColor = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255));

                lblMessage2.ForeColor = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255));

                //this.BackColor = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255));

                this.BackgroundImage = imgListScreen.Images[rnd.Next(3)];

            }

           

           

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

            lblMessage.ForeColor = Color.OrangeRed;

            this.BackColor = Color.Blue;

            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;

            this.ShowInTaskbar = false;

        }

 

        private void Form1_KeyPress(object sender, KeyPressEventArgs e)

        {

            this.Close();

        }

 

        private void Form1_KeyDown(object sender, KeyEventArgs e)

        {

            this.Close();

        }

 

        private void Form1_MouseClick(object sender, MouseEventArgs e)

        {

            this.Close();

        }

//You could add any other ways of closing the application as you wish to in addition to what is specified here...

    }

}

 

 

Thats it, you are done with the coding of a simple application which just moves the labels once the labels touches the edges of the corners, they change the direction and the backcolor and forecolor chnages as well...

With the imageList, if you have proper images you can toggle the images as well as specified in the code...

 

Now, the important part is to build this to the exe and make a screensaver out of it...

 

To throw some light on Screensavers, the extension for the screensaver files in our operating system are .scr and mostly available under C:\Windows\System32 if your operating system in installed in C Drive.

 

Now, the generated exe of the application needs to be copied to this folder ( C:\Windows\System32) and once it is copied, just change the extension from exe to .scr (ignore the warning).

 

Now, we are into final step...

Right click on your desktop and click on Personalize, choose Screen Saver.

You could find the newly copied screensaver in the list, select that apply the settings as you wish and enjoy the newly created screensaver using .net flash on your screen...

 

The above steps are specific to the Windows Vista and if you are using Windows XP or any other Operating system, most of the steps are same except, right click on the desktop and choose properties and then proceed further...

By Santhosh N   Popularity  (1425 Views)
Picture
Biography - Santhosh N
Having around 7 years of experience in designing and implementing software products including windows, console, service oriented and ofcourse predominantly on Web with .Net, XML, Javascript, Oracle, SQL Server.
My Blog