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

Implement Windows Based Screen Saver. (Source Part)

Author: Zunnair

In this article I will explain you the way in which we can Create the screen saver using VB.net. 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 vb.net 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()

 

        m_Options.LoadOptions()

        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

        Application.Exit()

    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

        DrawShape()

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))

        Else

            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)

        Else

            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.

Notes:

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
Top site, I hadn't noticed www.devasp.net before during my searches!
Carry on the wonderful work!

Posted on 8/25/2010 11:15:22 AM by heartburn diet

Thanks for sharing this link, but unfortunately it seems to be down... Does anybody have a mirror or another source? Please answer to my post if you do!

I would appreciate if a staff member here at www.devasp.net could post it.

Thanks,
James

Posted on 9/7/2010 5:43:00 AM by play solitaire online

Thanks for sharing the link, but unfortunately it seems to be offline... Does anybody have a mirror or another source? Please reply to my post if you do!

I would appreciate if a staff member here at www.devasp.net could post it.

Thanks,
Jack

Posted on 9/27/2010 7:22:05 PM by watch the social network online

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Implement Windows Based Screen Saver. (Description Part)

Disclaimer - Privacy
© 2002-2017 DevASP.net