Click here to Skip to main content
15,889,216 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Function in Linq Pin
Richard MacCutchan28-Dec-13 23:15
mveRichard MacCutchan28-Dec-13 23:15 
QuestionVB Photo Screensaver Pin
Nate Schoonover27-Dec-13 17:33
Nate Schoonover27-Dec-13 17:33 
AnswerRe: VB Photo Screensaver Pin
Eddy Vluggen29-Dec-13 3:13
professionalEddy Vluggen29-Dec-13 3:13 
GeneralRe: VB Photo Screensaver Pin
Nate Schoonover29-Dec-13 5:37
Nate Schoonover29-Dec-13 5:37 
GeneralRe: VB Photo Screensaver Pin
Eddy Vluggen29-Dec-13 17:15
professionalEddy Vluggen29-Dec-13 17:15 
GeneralRe: VB Photo Screensaver Pin
Nate Schoonover31-Dec-13 9:00
Nate Schoonover31-Dec-13 9:00 
GeneralRe: VB Photo Screensaver Pin
Eddy Vluggen2-Jan-14 9:18
professionalEddy Vluggen2-Jan-14 9:18 
GeneralRe: VB Photo Screensaver Pin
Nate Schoonover2-Jan-14 11:37
Nate Schoonover2-Jan-14 11:37 
Thanks Eddy! I will get rid of the picturebox as you suggested, one less thing to slow things down. I think writing up a draft would be a good idea. I will post it in a few days.

I have a few other things I need to sort out first. I am having trouble with loading settings using the base code I borrowed from Gertz. http://blogs.msdn.com/b/vbteam/archive/2009/01/23/an-updated-screensaver-example-matt-gertz.aspx?[^]

Most of the example code works great, but when I install the screensaver and use the config mode to define the source folder and other settings, the final settings are not used when the screen saver executes via Windows.

This is strange because the settings are used correctly in preview mode. However, when the Windows timer sets off the screensaver all the settings go back to default. This is the correct behavior if the screensaver does not detect any previous settings, but I can't figure out why it would load settings correctly in preview mode and not the regular mode.

The settings are being stored correctly in the User\AppData folder. There is nothing obviously wrong with the code, I am afraid I am missing something stupid.

For what it's worth I posted the code to the Options form below, but I recon you will have to see it all together to really understand it.

Options.vb
VB
Option Strict On

Imports System.Collections.ObjectModel

''' <summary>
''' This is the class that holds the Options information.  The Options information
'''   is defined as a class so that it can be easily serialized and deserialized.
''' </summary>
''' <remarks></remarks>
Public Class Options

#Region "Member variables"
    Private m_Speed As Integer = 3 'in seconds
    Private m_ShowTags As Boolean = True
    Private m_ShowDates As Boolean = True
    Private m_UseSubdirectories As Boolean = True
    Private m_Directory As String = "" 'directory to pull photos from
    Private m_files As ReadOnlyCollection(Of String) ' List of files
#End Region

#Region "Class Properties"
    ''' <summary>
    ''' Set or get whether or not to show the date
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property ShowDate() As Boolean
        Get
            Return m_ShowDates
        End Get
        Set(ByVal Value As Boolean)
            m_ShowDates = Value
        End Set
    End Property

    ''' <summary>
    ''' Set or get whether or not to look in subdirectories for pictures
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property UseSubdirectories() As Boolean
        Get
            Return m_UseSubdirectories
        End Get
        Set(ByVal Value As Boolean)
            m_UseSubdirectories = Value
        End Set
    End Property

    ''' <summary>
    ''' Set or get whether or not to show tags
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property ShowTags() As Boolean
        Get
            Return m_ShowTags
        End Get
        Set(ByVal Value As Boolean)
            m_ShowTags = Value
        End Set
    End Property

    ''' <summary>
    ''' Set or get which directory to look in for pictures
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Directory() As String
        Get
            Return m_Directory
        End Get
        Set(ByVal Value As String)
            m_Directory = Value
        End Set
    End Property

    ''' <summary>
    ''' Set or get what speed at which to show pictures
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Speed() As Integer
        Get
            Return m_Speed
        End Get
        Set(ByVal Value As Integer)
            m_Speed = Value
        End Set
    End Property

#End Region

#Region "Class Methods"
    ''' <summary>
    ''' This function loads the user defined options from the application settings file.
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub LoadOptions()
        Me.Speed = 16 'My.Settings.Speed
        Me.ShowDate = My.Settings.ShowDate
        Me.ShowTags = My.Settings.ShowTags
        Me.Directory = My.Settings.Directory
        Me.UseSubdirectories = My.Settings.UseSubdirectories

        If String.IsNullOrEmpty(Me.Directory) Then ' Default to "My Pictures" if not initialized
            Me.Directory = My.Computer.FileSystem.SpecialDirectories.MyPictures
         end If

        If Me.UseSubdirectories = True Then
            m_files = My.Computer.FileSystem.GetFiles(Me.Directory, FileIO.SearchOption.SearchAllSubDirectories, "*.jpg")
        Else
            m_files = My.Computer.FileSystem.GetFiles(Me.Directory, FileIO.SearchOption.SearchTopLevelOnly, "*.jpg")
        End If

    End Sub

    ''' <summary>
    ''' This function saves the user defined options to the application settings file.
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub SaveOptions()
        My.Settings.Speed = Me.Speed
        My.Settings.ShowDate = Me.ShowDate
        My.Settings.ShowTags = Me.ShowTags
        If Not String.IsNullOrEmpty(Directory) Then ' Don't bother saving
            My.Settings.Directory = Me.Directory
            My.Settings.Save()
        End If
        My.Settings.UseSubdirectories = Me.UseSubdirectories
        My.Settings.Save()


        If Me.UseSubdirectories = True Then
            m_files = My.Computer.FileSystem.GetFiles(Me.Directory, FileIO.SearchOption.SearchAllSubDirectories, "*.jpg")
        Else
            m_files = My.Computer.FileSystem.GetFiles(Me.Directory, FileIO.SearchOption.SearchTopLevelOnly, "*.jpg")
        End If

    End Sub

#End Region



End Class



And here is where the screensaver form is supposed to load the saved settings using the form's Load event:

VB
Option Strict On

Imports System.Windows.Media.Imaging
Imports System.IO
Imports System.Collections.ObjectModel
Imports System.Collections.Generic

' This form is the main form for the screen saver. It does all the painting
'   of the screen, and handles when it should terminate and release control 
'   back to Windows.
Public Class frmScreenSaver

#Region "Variables"
    ' Declare the class variables that will be used for the Screen Saver.
    ' Options object that contains information about the user selected options
    Private m_Options As New Options()

    ' Random object to support the drawing
    Private m_Random As New Random()

    ' Used to for first setting MouseMove location
    Private m_IsActive As Boolean = False

    ' Used to determine if the Mouse has actually been moved
    Private m_MouseLocation As Point

    Private m_files As ReadOnlyCollection(Of String) ' List of files
    Private m_fileCount As Integer = 0
#End Region

#Region "Events"
    ''' <summary>
    ''' This subroutine initializes the Screen Saver form when it is loaded
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub frmSceenSaver_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Debug = False
        ' Load the Saved options. 
        m_Options.LoadOptions()

        ' Reset location of label
        SetLabelLocation()

        ' Set the speed based on the user defined Options.
        Me.tmrUpdateScreen.Interval = m_Options.Speed * 1000

        ' Enable the timers.
        Me.tmrUpdateScreen.Enabled = True
        Me.AnimationTimer.Enabled = True

        If m_Options.UseSubdirectories = True Then
            m_files = My.Computer.FileSystem.GetFiles(m_Options.Directory, FileIO.SearchOption.SearchAllSubDirectories, "*.jpg")
        Else
            m_files = My.Computer.FileSystem.GetFiles(m_Options.Directory, FileIO.SearchOption.SearchTopLevelOnly, "*.jpg")
        End If
        If m_files IsNot Nothing Then
            m_fileCount = m_files.Count
        Else
            Me.lblDescription.Text = "No pictures found!"
            SetLabelLocation()
        End If
        Windows.Forms.Cursor.Hide()
        If m_fileCount <> 0 Then
            DrawPicture()
        End If
    End Sub


I left off the rest of the event handles that control the picture drawing and animation, but if you think it would be helpful I can throw that up here too.

Thanks again for your time here! Just let me know if you have any questions about the code. I just can't figure out why the saved settings won't load when executing the screensaver in regular mode.

Nate
GeneralRe: VB Photo Screensaver Pin
Eddy Vluggen4-Jan-14 3:41
professionalEddy Vluggen4-Jan-14 3:41 
GeneralRe: VB Photo Screensaver Pin
Nate Schoonover4-Jan-14 18:17
Nate Schoonover4-Jan-14 18:17 
GeneralRe: VB Photo Screensaver Pin
Eddy Vluggen5-Jan-14 1:25
professionalEddy Vluggen5-Jan-14 1:25 
QuestionDataGridView populates only first row Pin
Sonhospa27-Dec-13 9:16
Sonhospa27-Dec-13 9:16 
AnswerRe: DataGridView populates only first row Pin
Eddy Vluggen29-Dec-13 2:51
professionalEddy Vluggen29-Dec-13 2:51 
AnswerRe: DataGridView populates only first row Pin
Sonhospa29-Dec-13 7:08
Sonhospa29-Dec-13 7:08 
GeneralRe: DataGridView populates only first row Pin
Eddy Vluggen29-Dec-13 17:12
professionalEddy Vluggen29-Dec-13 17:12 
QuestionLINQ Pin
tsunamigang23-Dec-13 18:04
tsunamigang23-Dec-13 18:04 
AnswerRe: LINQ Pin
thatraja23-Dec-13 20:09
professionalthatraja23-Dec-13 20:09 
GeneralRe: LINQ Pin
tsunamigang23-Dec-13 22:08
tsunamigang23-Dec-13 22:08 
QuestionProgressbar value not accurate? Pin
Sonhospa21-Dec-13 0:50
Sonhospa21-Dec-13 0:50 
AnswerRe: Progressbar value not accurate? Pin
Dave Kreskowiak21-Dec-13 4:50
mveDave Kreskowiak21-Dec-13 4:50 
NewsRe: Progressbar value not accurate? Pin
Sonhospa21-Dec-13 9:04
Sonhospa21-Dec-13 9:04 
GeneralRe: Progressbar value not accurate? Pin
Dave Kreskowiak21-Dec-13 11:34
mveDave Kreskowiak21-Dec-13 11:34 
QuestionVerification Failure (DigitalPersona 4000B) Pin
Member 1048039921-Dec-13 0:35
Member 1048039921-Dec-13 0:35 
AnswerRe: Verification Failure (DigitalPersona 4000B) Pin
Dave Kreskowiak21-Dec-13 4:46
mveDave Kreskowiak21-Dec-13 4:46 
QuestionException Pin
tsunamigang19-Dec-13 20:10
tsunamigang19-Dec-13 20:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.