Solved

ALLOW USER TO CHANGE PICTURE FROM FOLDER

Posted on 2011-02-20
11
775 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with solving error related to resources file 4 48
Sql server insert 13 32
VB.NET 2008 Winforms Signing 13 20
Complex SQL statement in VB.NET 7 16
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

822 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