Solved

ALLOW USER TO CHANGE PICTURE FROM FOLDER

Posted on 2011-02-20
11
774 Views
Last Modified: 2012-05-11
Hi All,

I have windows application.

I want to allow user to change picture from shown picturebox.
Next time the form called again, it remains the new one changed by user.

How could I do it ?

Thank you.
0
Comment
Question by:emi_sastra
  • 6
  • 5
11 Comments
 
LVL 8

Expert Comment

by:Toxacon
ID: 34937214
You need to store information about the selected image/picture somewhere (in registry, for example). Next time the user starts the application, it reads the stored information and selects displayed image/picture accordingly.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 34939792
Hi Toxacon,

There will be a lot of things like that.
How we organize it at registry ?

Thank you.
0
 
LVL 8

Expert Comment

by:Toxacon
ID: 34940765
This is what to do:

Let's say you have company "Software Unlimited Inc" and your software is called "Photos Unlimited 1.0"

You'd create a key in Software\SoftwareUnlimited\PhotosUnlimited\1.0

Under that key you store values like String: "SelectedImage" Value: "Image003"

Per-user settings go to HKEY_Current_User (HKCU), so use this for user selections. Users can write to their own registry key.

Of course, if your software has multiple portions you can add additional registry keys to use to sort data:

HKCU\Software\SoftwareUnlimited\PhotosUnlimited\1.0\UserPreferences
HKCU\Software\SoftwareUnlimited\PhotosUnlimited\1.0\ImageGallery
HKCU\Software\SoftwareUnlimited\PhotosUnlimited\1.0\FormData

0
 
LVL 1

Author Comment

by:emi_sastra
ID: 34940996
Which one will be the best.

1. Registry
2. Files or Database.

What will be happened when the computer is going to formatted ?

Thank you.
0
 
LVL 8

Expert Comment

by:Toxacon
ID: 34941522
It depends...

Registry pros:
- Easy to use

Registry cons:
- Difficult to transfer

Simple file pros:
- Easy to transfer

Simple file cons:
- Need to develop a settings parser

XML file pros:
- Standardized
- Easy to transfer

XML file cons:
- No?

Database pros:
- Central place to store settings

Database cons:
- Requires network connection


If the disk is formatted, the registry data will be gone. A file can be put on user's home directory on a server so it will survive formatting. A central database will also work that way.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:emi_sastra
ID: 34941564
XML is the best to store those information ?

Thank you
0
 
LVL 8

Expert Comment

by:Toxacon
ID: 34941663
Yes, if you know how to construct classes to store information. You can quite easily write contents of a class to XML file and vice versa.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 34947913
I want to learn from the experts.

Would you please provide code for me?

Thank you.
0
 
LVL 8

Expert Comment

by:Toxacon
ID: 34953317
Do you know how to create your own classes or do you need only the XML Reader/Writer code?
0
 
LVL 8

Accepted Solution

by:
Toxacon earned 500 total points
ID: 34988275
Ok, I assume you don't know how to create a class for this purpose, so i wrote some code to save and load settings to and from network share.

Imports System.IO

Public Class Form1
    Dim Settings As New FileSettingsSaver
    Const NetworkPath As String = "\\server\share"
    Dim SettingsFile As String = NetworkPath & "\" & Environ$("USERNAME") & "_Settings.xml"

    Public Sub SaveSettingsToNetwork()
        With Settings
            .SelectedImageName = "MySelectedImage"
            .MyOtherSetting = 35
        End With
        XML_WriteFile(SettingsFile, Settings)
    End Sub

    Public Sub LoadSettingsFromNetwork()
        Settings = XML_ReadFile(SettingsFile)
        If Not IsNothing(Settings) Then
            MsgBox(Settings.SelectedImageName)
            MsgBox(Settings.MyOtherSetting)
        End If
    End Sub

    Private Function XML_ReadFile(ByVal _FileName As String) As FileSettingsSaver
        Dim Data As New FileSettingsSaver
        Dim srFile As StreamReader
        Try
            If File.Exists(_FileName) = False Then
                Return Nothing
            End If
            srFile = New StreamReader(_FileName, System.Text.Encoding.UTF8)
            Dim oXmlReader As New System.Xml.Serialization.XmlSerializer(GetType(FileSettingsSaver))
            Data = oXmlReader.Deserialize(srFile)
            srFile.Close()
        Catch ex As Exception
            Return Nothing
        End Try
        Return Data
    End Function

    Private Function XML_WriteFile(ByVal _FileName As String, ByVal _Doc As FileSettingsSaver) As Integer
        Try
            Dim XmlWriter As New System.Xml.Serialization.XmlSerializer(GetType(FileSettingsSaver))
            Dim swFile As New StreamWriter(_FileName)
            XmlWriter.Serialize(swFile, _Doc)
            swFile.Flush()
            swFile.Close()
            Return 0
        Catch
            Return Err.Number
        End Try
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        SaveSettingsToNetwork()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        LoadSettingsFromNetwork()
    End Sub
End Class

Public Class FileSettingsSaver
    Public SelectedImageName As String
    Public MyOtherSetting As Integer
End Class

Open in new window

0
 
LVL 1

Author Comment

by:emi_sastra
ID: 35090621
Hi Toxacon,

I am sorry, just back again.

It works.

Thank you very much for your help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now