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

Implement Windows Based Screen Saver. (Description Part)

Author: Zunnair

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 first part of that Topic.

Feature Highlights:

This how-to demonstrates many of the important features of creating screen savers that can be automated by Windows. Concepts demonstrated are:

  • Creating a screen saver to fill the screen with a single form, and draw images to the form.
  • Setting up an Options file, to store user defined options that guide how the screen saver runs.
  • React to mouse and keyboard events to close the screen saver.

The screen saver preview functionality is not demonstrated, since it involves several advanced threading issues.

For the Proper Understanding. Follow the steps below.

1. Create new application Using File menu and Choose project. Now you will see the form Open in your application.


2. Now write the region of code below. It Actually <System.Diagnostics.DebuggerStepThrough()> has been added to some procedures since they are not the focus of the demo. Remove them if you wish to debug the procedures.This code simply shows the About form. Also have a code that will close the form.


#Region " Standard Menu Code "



Private Sub mnuAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAbout.Click

End Sub




Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click


End Sub


#End Region


3-double click on install button that will generate the click Event. This button installs the demo screen saver on your machine by copying the SCR file to your Windows System directory. Try to install the screen saver. If not successful, then show the error to the user.


Private Sub btnInstall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInstall.Click 

Dim fileName As String = "VB_NET How-To ScreenSaver.scr"

Dim sourceFile As String = Environment.CurrentDirectory & "\..\" & fileName

Dim destFile As String = Environment.SystemDirectory & "\" & fileName



      File.Copy(sourceFile, destFile, True)


 Catch ex As Exception


      MsgBox(ex.ToString(), MsgBoxStyle.Exclamation, Me.Text)


 End Try



End Sub


Now double click on form to generate the load event of form.and write the code below. This code loads the current user defined options and sets the UI elements in this form to their proper values. Load the options file.  Recall that the load method will always return an options object, even if the file doesn't currently exist


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

        Dim myOptions As New Options()



        Me.cboSpeed.Text = myOptions.Speed

        Me.chkTransparent.Checked = myOptions.IsTransparent


        If myOptions.Shape = "Ellipses" Then

            Me.optEllipses.Checked = True


            Me.optRectangles.Checked = True

        End If

 End Sub   


Now double click on ok button and the code below. This code changes the values in the Options object to the new user selected values, and saves it to disk.


Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Dim myOptions As New Options()


        If Me.optEllipses.Checked Then

            myOptions.Shape = "Ellipses"


            myOptions.Shape = "Rectangles"

        End If

        myOptions.IsTransparent = Me.chkTransparent.Checked

        myOptions.Speed = Me.cboSpeed.Text




 End Sub

Add Article Comment:
Name :
Email Address :
Comments :
<< Implementing Exception handling in Visual Basic.Net 2.0

Disclaimer - Privacy
© 2002-2017