Question Save instructions/settings

N3xus

New member
Joined
Jun 20, 2013
Messages
3
Programming Experience
1-3
Hey guys, I've been doing a browser for myself.
Everything works fine and I'm creating a lot of shortcuts so I can do almost everything from there but there's a little problem;
I created a form and there are settings, for example theme changer, anti popup enabled and so on.
I have a theme for the setting form too, but when I close it and I open it again the theme is always the standard one and every other setting every time I close the browser is resetted.
How can I "save" those settings? I've been trying to do it for the entire day, I'm a newbie with these things and I'm studying to become a developer and I'm just at the 3rd year, so please don't be rude :black_eyed:
 
Last edited:
Hi,

You can use the Settings page in the Application Properties window (via the Projects Menu) to add settings to your application which can be saved when a Form is then closed. Lets say you want to save a Text value in a TextBox, you would do the following:-

1) Add a new setting in the Settings page called "myTextBoxSetting".
2) Add a TextBox to a Form and open the Properties window.
3) Expand the Application Settings sub menu and click the ellipses of the PropertyBinding.
4) Select Text as the Property to be bound and drop the ComboBox down to select the Setting to be Bound to the TextBox.
(Note: at this point, you can also create a new setting here to be bound to the selected property)

That's it. Now when you open and close your form your settings will be persisted.

Hope that helps.

Cheers,

Ian
 
Thanks Ian, that helped me a lot, I can save everything now except the background image because on the settings page there is nothing like System.Drawing.Image.
 
Thanks Ian, that helped me a lot, I can save everything now except the background image because on the settings page there is nothing like System.Drawing.Image.

Probably the best option is to store the image data as a base-64 string. That's exactly what the IDE does when you store an image in resources. Here are a pair of methods that will convert an Image object to a base-64 String and back again:
Private Function ToBase64String(img As Image) As String
    Using stream As New MemoryStream
        img.Save(stream, img.RawFormat)

        Return Convert.ToBase64String(stream.GetBuffer())
    End Using
End Function

Private Function ToImage(base64Text As String) As Image
    Using stream As New MemoryStream(Convert.FromBase64String(base64Text))
        Return Image.FromStream(stream)
    End Using
End Function
Sample usage:
Dim str = ToBase64String(PictureBox1.Image)

MessageBox.Show(str)

PictureBox2.Image = ToImage(str)
You can then just use a setting of type String to store the base-64 data.
 
Back
Top