views:

819

answers:

4

I'm developing a piece in VB.NET. Inside my primary form, I'm creating a new form to use as a dialog. I was wondering if there was a way to, upon the close of the new dialog, save it's size settings for each user (probably in a file on their machine, through XML or something?)

+2  A: 

Although this is for C#, it will help with VB.Net as well.

Kris Erickson
A: 

You can also do this using the UI provided by the VB.NET IDE itself. In the properties pane for a form, look under the item called "(Application Settings)" and then under "Property Binding." You can bind just about every property of the form (including size and location) to a settings value for that application.

Keithius
+4  A: 

you can save it to the settings file, and update it on the 'onclosing' event.

to make a setting goto Project Properties ->settings -> then make a setting like 'dialogsize' of type system.drawing.size.

then do this in your dialog form:

Public Sub New()
    InitializeComponent()
End Sub

Public Sub New(ByVal userSize As Size)
    InitializeComponent()
    Me.Size = userSize
End Sub

Protected Overrides Sub OnClosing(ByVal e As System.ComponentModel.CancelEventArgs)
    MyBase.OnClosing(e)
    My.Settings.DialogSize = Me.Size
    My.Settings.Save()
End Sub

do something like this to check and use the setting:

    Dim dlg As MyDialogWindow
    If My.Settings.DialogSize.IsEmpty Then
        dlg = New MyDialogWindow()
    Else
        dlg = New MyDialogWindow(My.Settings.DialogSize)
    End If
    dlg.ShowDialog()
Hath
In the designer for my WinForm, I go under Properties and I see (PropertyBinding), but there is no DialogSize property that I can find. Is this something you set up manually in code or in the designer?
Joe Morgan
DialogSize is a global Var that you need to make in the settings file.Goto Project->'you project name' properties - > Settings tab-> add a setting called "DialogSize" or what ever you like of type System.Drawing.SizeUnfortunatly size is not in the propertybinding bit
Hath
Ok - I figured out what you were talking about and got it set up, but now when I try to invoke it, I get a ConfigurationErrorsException, saying that the Cofniguration system failed to initialize. How do I go about resolving this?
Joe Morgan
A: 

As it turns out, I found a way to do this using the System.IO.IsolatedStorage

Joe Morgan
Interesting - why did you choose IsolatedStorage?
Keithius
Care to share your code?
David Vidmar