*/
Are you blogging on PH? Get your free blog.
*/

View FuzzyScreen\FuzzyScreen\frmOptions.vb

Vb.Net screensaver 1.0

Submitted By: FuzzyDaze
Rating: starstarstarstarstar (Rate It)


Imports FileWriter.FileWriter

Public Class frmOptions
        Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

        Public Sub New()
                MyBase.New()

                'This call is required by the Windows Form Designer.
                InitializeComponent()

                'Add any initialization after the InitializeComponent() call

        End Sub

        'Form overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
                If disposing Then
                        If Not (components Is Nothing) Then
                                components.Dispose()
                        End If
                End If
                MyBase.Dispose(disposing)
        End Sub

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer. 
        'Do not modify it using the code editor.
        Friend WithEvents lstImages As System.Windows.Forms.ListBox
        Friend WithEvents btnClose As System.Windows.Forms.Button
        Friend WithEvents txtDelay As System.Windows.Forms.TextBox
        Friend WithEvents lblDelay As System.Windows.Forms.Label
        Friend WithEvents btnSave As System.Windows.Forms.Button
        Friend WithEvents btnAddImage As System.Windows.Forms.Button
        Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
        Friend WithEvents btnRemoveImage As System.Windows.Forms.Button
        Friend WithEvents lblImages As System.Windows.Forms.Label
        Friend WithEvents btnRun As System.Windows.Forms.Button
        Friend WithEvents chkRandomize As System.Windows.Forms.CheckBox
    Friend WithEvents btnMoveUp As System.Windows.Forms.Button
    Friend WithEvents btnMoveDown As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmOptions))
        Me.lstImages = New System.Windows.Forms.ListBox
        Me.btnClose = New System.Windows.Forms.Button
        Me.txtDelay = New System.Windows.Forms.TextBox
        Me.lblDelay = New System.Windows.Forms.Label
        Me.btnSave = New System.Windows.Forms.Button
        Me.btnAddImage = New System.Windows.Forms.Button
        Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
        Me.btnRemoveImage = New System.Windows.Forms.Button
        Me.lblImages = New System.Windows.Forms.Label
        Me.btnRun = New System.Windows.Forms.Button
        Me.chkRandomize = New System.Windows.Forms.CheckBox
        Me.btnMoveUp = New System.Windows.Forms.Button
        Me.btnMoveDown = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'lstImages
        '
        Me.lstImages.Location = New System.Drawing.Point(32, 88)
        Me.lstImages.Name = "lstImages"
        Me.lstImages.Size = New System.Drawing.Size(416, 303)
        Me.lstImages.TabIndex = 0
        '
        'btnClose
        '
        Me.btnClose.Location = New System.Drawing.Point(352, 16)
        Me.btnClose.Name = "btnClose"
        Me.btnClose.Size = New System.Drawing.Size(96, 24)
        Me.btnClose.TabIndex = 1
        Me.btnClose.Text = "Exit"
        '
        'txtDelay
        '
        Me.txtDelay.Location = New System.Drawing.Point(32, 32)
        Me.txtDelay.Name = "txtDelay"
        Me.txtDelay.Size = New System.Drawing.Size(136, 20)
        Me.txtDelay.TabIndex = 2
        Me.txtDelay.Text = ""
        '
        'lblDelay
        '
        Me.lblDelay.Location = New System.Drawing.Point(32, 16)
        Me.lblDelay.Name = "lblDelay"
        Me.lblDelay.Size = New System.Drawing.Size(136, 16)
        Me.lblDelay.TabIndex = 3
        Me.lblDelay.Text = "Delay in seconds"
        '
        'btnSave
        '
        Me.btnSave.Location = New System.Drawing.Point(352, 48)
        Me.btnSave.Name = "btnSave"
        Me.btnSave.Size = New System.Drawing.Size(96, 24)
        Me.btnSave.TabIndex = 4
        Me.btnSave.Text = "Save"
        '
        'btnAddImage
        '
        Me.btnAddImage.Location = New System.Drawing.Point(32, 400)
        Me.btnAddImage.Name = "btnAddImage"
        Me.btnAddImage.Size = New System.Drawing.Size(104, 24)
        Me.btnAddImage.TabIndex = 5
        Me.btnAddImage.Text = "Add Image"
        '
        'OpenFileDialog1
        '
        Me.OpenFileDialog1.Multiselect = True
        '
        'btnRemoveImage
        '
        Me.btnRemoveImage.Location = New System.Drawing.Point(352, 400)
        Me.btnRemoveImage.Name = "btnRemoveImage"
        Me.btnRemoveImage.Size = New System.Drawing.Size(96, 24)
        Me.btnRemoveImage.TabIndex = 8
        Me.btnRemoveImage.Text = "Remove"
        '
        'lblImages
        '
        Me.lblImages.Location = New System.Drawing.Point(32, 72)
        Me.lblImages.Name = "lblImages"
        Me.lblImages.Size = New System.Drawing.Size(128, 16)
        Me.lblImages.TabIndex = 9
        Me.lblImages.Text = "Images"
        '
        'btnRun
        '
        Me.btnRun.Location = New System.Drawing.Point(248, 16)
        Me.btnRun.Name = "btnRun"
        Me.btnRun.Size = New System.Drawing.Size(96, 24)
        Me.btnRun.TabIndex = 10
        Me.btnRun.Text = "Close && Run"
        '
        'chkRandomize
        '
        Me.chkRandomize.Location = New System.Drawing.Point(256, 48)
        Me.chkRandomize.Name = "chkRandomize"
        Me.chkRandomize.Size = New System.Drawing.Size(88, 24)
        Me.chkRandomize.TabIndex = 11
        Me.chkRandomize.Text = "Randomize"
        '
        'btnMoveUp
        '
        Me.btnMoveUp.Location = New System.Drawing.Point(144, 400)
        Me.btnMoveUp.Name = "btnMoveUp"
        Me.btnMoveUp.Size = New System.Drawing.Size(96, 24)
        Me.btnMoveUp.TabIndex = 12
        Me.btnMoveUp.Text = "Move Up"
        '
        'btnMoveDown
        '
        Me.btnMoveDown.Location = New System.Drawing.Point(248, 400)
        Me.btnMoveDown.Name = "btnMoveDown"
        Me.btnMoveDown.Size = New System.Drawing.Size(96, 24)
        Me.btnMoveDown.TabIndex = 13
        Me.btnMoveDown.Text = "Move Down"
        '
        'frmOptions
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(480, 440)
        Me.Controls.Add(Me.btnMoveDown)
        Me.Controls.Add(Me.btnMoveUp)
        Me.Controls.Add(Me.chkRandomize)
        Me.Controls.Add(Me.btnRun)
        Me.Controls.Add(Me.lblImages)
        Me.Controls.Add(Me.btnRemoveImage)
        Me.Controls.Add(Me.btnAddImage)
        Me.Controls.Add(Me.btnSave)
        Me.Controls.Add(Me.lblDelay)
        Me.Controls.Add(Me.txtDelay)
        Me.Controls.Add(Me.btnClose)
        Me.Controls.Add(Me.lstImages)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.MaximizeBox = False
        Me.Name = "frmOptions"
        Me.Text = "Options"
        Me.ResumeLayout(False)

    End Sub

#End Region

        Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
                '** close the form and automatically exit the program
                Me.Close()
        End Sub

        Private Sub frmOptions_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                '** Load the settings into the form
                txtDelay.Text = intDelay
                chkRandomize.Checked = booRandomize
               
                '** Load the images to the form, use the original dataset to preserve the order.
                Dim intAddImage As Integer
                intImageCount = datScreenData.Tables(strTableName).Rows.Count
                If intImageCount > 0 Then
                        If datScreenData.Tables(strTableName).Rows(0).Item(strColumnName) = Nothing Then
                        Else
                                For intAddImage = 0 To intImageCount - 1
                                lstImages.Items.Add(datScreenData.Tables(strTableName).Rows(intAddImage).Item(strColumnName))
                                Next
                        End If
                End If
        End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Dim intAddImage As Integer = 0
        ReDim strImageList(lstImages.Items.Count)
        Dim strImages As String

        '** Clear the original dataset images and add the settings and images from the form to it
        datScreenData.Tables(strTableName).Rows.Clear()
        Try
            '** Set the variables with the new settings.
            intDelay = Val(txtDelay.Text)
            booRandomize = chkRandomize.Checked
        Catch ex As Exception
            MessageBox.Show("Unable to update the settings. Please reload the program.")
        End Try
        For intAddImage = 0 To lstImages.Items.Count - 1
            strImageList(intAddImage) = lstImages.Items(intAddImage)
            Dim tRow As DataRow = datScreenData.Tables(strTableName).NewRow
            datScreenData.Tables(strTableName).Rows.Add(tRow)
            datScreenData.Tables(strTableName).Rows(intAddImage).Item(strColumnName) = lstImages.Items(intAddImage)
           
            '** add the images to the imagestring used to write a new xml file.
            strImages &= vbTab & vbTab & "<ImageName>" & lstImages.Items(intAddImage) & "</ImageName>" & vbCrLf
        Next
        '** Write a new xml file using the images just added. The other settings will be applied in the CreateXmlFile function.
        CreateXmlFile(strImages)
    End Sub

    Private Sub btnAddImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddImage.Click
        '** Set the OpenDialog filter to show only image files
        OpenFileDialog1.Filter = "All Image Files(*.BMP;*.GIF;*.JPG;*.JPEG;*.PNG;*.EMF;*.WMF)|*.BMP;*.GIF;*.JPG;*.JPEG;*.PNG;*.EMF;*.WMF|Bitmap Files(*.BMP;*.GIF;*.JPG;*.JPEG;*.PNG)|*.BMP;*.GIF;*.JPG;*.JPEG;*.PNG|MetaFiles(*.EMF;*.WMF)|*.EMF;*.WMF"
        If OpenFileDialog1.ShowDialog = DialogResult.OK Then
            '** If the user clicks OK on the OpenFileDialog add all selected images
            Dim FileName As String
            For Each FileName In OpenFileDialog1.FileNames
                lstImages.Items.Add(FileName)
            Next
           
            '** Move the list to the last image added
            lstImages.TopIndex = lstImages.Items.Count - 1
        End If
    End Sub

    Private Sub btnRemoveImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemoveImage.Click
        '** check to see if an image was selcted and next remove it from the list.
        If lstImages.SelectedIndex > -1 Then
            lstImages.Items.Remove(lstImages.SelectedIndex)
        Else
            MessageBox.Show("Select an image first")
        End If
    End Sub

    Private Sub btnRun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRun.Click
        '** Run the screensaver and exit the program if the screensaver quits.
        If CheckFile(strInputFile) Then
            If LoadInputFile() Then
                ShowScreenSaver()
                Application.Exit()
            End If
        End If
    End Sub

    Private Sub ShowScreenSaver()
        '** Show the screensaver form
        Dim screenSaverForm As New FuzzyScreen.frmFuzzyScreen
        screenSaverForm.ShowDialog()
    End Sub


    Private Sub btnMoveUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveUp.Click
        '** Move the selected image 1 place up
        Dim strTempImage As String
        If lstImages.SelectedIndex > 0 Then
            strTempImage = lstImages.Items(lstImages.SelectedIndex - 1)
            lstImages.Items(lstImages.SelectedIndex - 1) = lstImages.Items(lstImages.SelectedIndex)
            lstImages.Items(lstImages.SelectedIndex) = strTempImage
            lstImages.SelectedIndex -= 1
        End If
    End Sub

    Private Sub btnMoveDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveDown.Click
        '** Move the selected image 1 place down
        Dim strTempImage As String
        If lstImages.SelectedIndex > 0 Then
            strTempImage = lstImages.Items(lstImages.SelectedIndex + 1)
            lstImages.Items(lstImages.SelectedIndex + 1) = lstImages.Items(lstImages.SelectedIndex)
            lstImages.Items(lstImages.SelectedIndex) = strTempImage
            lstImages.SelectedIndex += 1
        End If
    End Sub
End Class

corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.