Solved

ALLOW USER TO CHANGE PICTURE FROM FOLDER

Posted on 2011-02-20
11
777 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

733 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