Solved

ALLOW USER TO CHANGE PICTURE FROM FOLDER

Posted on 2011-02-20
11
776 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 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