Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
SQL Server

Creating Screen Saver Using Vb.Net.(Part 2)

Author: DevASP
Download Source Code : 566_Screen

In this article I will explain you the way in which we can Create the screen saver using This is Not so simple so I divide this Topic in two Parts. This is the Second part of that Topic.

 For the Proper Understanding. Follow the steps below.

1. Create new Form Using File menu and Choose project.

Now you will see the form Open in your application.


 2- Double click on form to generate the Load event of form.


This subroutine initializes the Screen Saver form when it is loaded.

Create the Graphics object to use when drawing.Load the Saved options. Remember that if no Options file exists, one will be created.

Set the speed based on the user defined Options.and also Enable the timer.


Private Sub frmSceenSaver_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.m_Graphics = Me.CreateGraphics()



        Select Case m_Options.Speed

            Case "Slow"

                Me.tmrUpdateScreen.Interval = 500

            Case "Fast"

                Me.tmrUpdateScreen.Interval = 100

            Case Else

                Me.tmrUpdateScreen.Interval = 200

        End Select


        Me.tmrUpdateScreen.Enabled = True


    End Sub    


The subroutine causes the screen saver to close if the user pushes a mouse button.


Private Sub frmSceenSaver_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown


    End Sub


This code is executed whenever the timer tick event if fired. It draws

a shape to the screen.


Private Sub tmrUpdateScreen_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrUpdateScreen.Tick


End Sub


Now the important Routine comes.This subroutine just draws a randomly colored, randomly sized, shapes to the screen, based on some user defined parameters. Get the largest possible values for the screen,Coordinates of random points' Rectangle to paint the shapes, color used to paint the shapes, Generate some random numbers to use as coordinates, Create a rectangle based on the randomly generated coordinates, Get a random color. If the user wants transparency then allow the, transparency to be randomly generated as well.  If not, then set the Alpha to 255 (the max).Draw an Ellipse or rectangle based on User defined options.


Private Sub DrawShape()

        Dim maxX As Integer = Me.Width

        Dim maxY As Integer = Me.Height


        Dim x1, x2, y1, y2 As Integer '

        Dim myRect As Rectangle       

        Dim myColor As Color

        x1 = m_Random.Next(0, maxX)

        x2 = m_Random.Next(0, maxX)


        y1 = m_Random.Next(0, maxY)

        y2 = m_Random.Next(0, maxY)


        myRect = New Rectangle(Math.Min(x1, x2), Math.Min(y1, y2), _

                Math.Abs(x1 - x2), Math.Abs(y1 - y2))



        If m_Options.IsTransparent Then

 myColor = Color.FromArgb(m_Random.Next(255), m_Random.Next(255), _

                m_Random.Next(255), m_Random.Next(255))


            myColor = Color.FromArgb(255, m_Random.Next(255), _

                m_Random.Next(255), m_Random.Next(255))

        End If


               If m_Options.Shape = "Ellipses" Then

            m_Graphics.FillEllipse(New SolidBrush(myColor), myRect)


            m_Graphics.FillRectangle(New SolidBrush(myColor), myRect)

        End If

    End Sub


Now Built and run the Project Your You will see the Tree menu in the combo box..

The source Code is given by this article for your Complete Understanding. Just run it you can understand how easily we can create it. 

Running the Sample:

To run the sample:

  1. Doubleclick the VB.NET How-To Creating a Screensaver using GDI+.sln file. 
  2. Click the "Install" button on the main form to copy the screen saver to the Windows system folder.
  3. Go into your display settings, and set the screen saver as VB.NET How-To Screen Saver.
  4. Test the screensaver.
  5. Explore the project for an example of creating your own screen saver.


When you compile your own screen saver, there are several things to keep in mind.  First, be sure to set the following Form Properties:

  • FormBorderStyle = None
  • WindowState = Maximized
  • MaximizeBox = False
  • MinimizeBox = False
  • ShowInTaskbar = False

Also, before you can use a newly compiled screen saver, you must change its extension from .EXE to .SCR, and copy it to the Windows system directory (by default, in WinXP this is "C:\Windows\System32").

Article Comments
need details about this article

Posted on 12/14/2006 7:12:38 AM by nadia

how to build screensaver in "vb"

Posted on 1/22/2007 11:05:47 AM by ankush kamtikar


am wandering how can i convert the .exe file to a .scr ....renaming is not the solution..

Posted on 1/30/2007 6:02:09 AM by FARAH

how to create a screen savers using visual basic

Posted on 2/11/2007 12:15:59 AM by gowrishankar

Creating Screen Saver Using Vb.Net.(Part 2)

Posted on 4/6/2007 2:44:09 AM by Senthil Kumar

Hello Sir,Please give the solution how to make the screen saver by using more than 2 pictures.acually I tried it,but by default in .NEt(Vb) it took two pictures.please also give the process of packaging software.

Posted on 8/20/2007 5:19:58 AM by Rathindra Nath Singha

hi, how do you change your [exe] to [scr], i tried it but the exe extension still there. i rename it to change the exe but is not working. Is that any way to change program extension to another in vb

Posted on 9/12/2007 11:03:23 PM by kay

I'm very thankfull to give your programm, it's more helpfull to me..

if u want to help me again plz send dotnet programmes(vb-coding).

Thank u

Posted on 12/11/2007 8:57:45 AM by Mahez

Hi, I like to know if there is a way to create something similar to a screensaver but for the desktop. I want my desktop background to change images by certain time intervals. Can it be done?

Posted on 2/12/2010 1:42:36 PM by bravo659

Hi, I like to know if there is a way to change images like the screensaver for the desktop?

Thanks I appreciate for your assistance.


Desi Bravo

Posted on 2/12/2010 1:44:04 PM by Desi Bravo

- People with problems changing extension .exe to .scr -

Sounds like you need to show full file extensions in your OS.

- In Windows XP, open any folder.
- At the top of the window, click on TOOLS,
- Click on the VIEW tab.
- Scroll down the ADVANCED SETTINGS and un-check the box that says HIDE EXTENSIONS FOR KNOWN FILE TYPES.
- Click on APPLY button
- Click on OK button

Now go back to the file and rename it with the extension you would like. Hope that helps.

Posted on 8/19/2010 8:15:33 PM by Marcel

Add Article Comment:
Name :
Email Address :
Comments :
<< Creating Screen Saver Using VB.Net (Part 1)

Disclaimer - Privacy
© 2002-2018