Solved

ALLOW USER TO CHANGE PICTURE FROM FOLDER

Posted on 2011-02-20
11
773 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 1

Author Comment

by:emi_sastra
Comment Utility
XML is the best to store those information ?

Thank you
0
 
LVL 8

Expert Comment

by:Toxacon
Comment Utility
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
Comment Utility
I want to learn from the experts.

Would you please provide code for me?

Thank you.
0
 
LVL 8

Expert Comment

by:Toxacon
Comment Utility
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
Comment Utility
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
Comment Utility
Hi Toxacon,

I am sorry, just back again.

It works.

Thank you very much for your help.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

15 Experts available now in Live!

Get 1:1 Help Now