Save Windows Form Size

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

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


You can also add a new setting to your application (size) and set it to system.drawing.size

Then, you make sure you save the current size to settings on close.

    Private Sub myForm_FormClosing(ByVal sender As System.Object,
                          ByVal e As System.Windows.Forms.FormClosingEventArgs) _
                             Handles MyBase.FormClosing

    My.Settings.size = Me.Size
    My.Settings.Save()

End Sub

and on load you apply the size you have saved in settings

    Private Sub myForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles MyBase.Load
    ' if  this is the first  time to load the form 
    ' dont set the size ( the form will load  with the size  in the designe)
    If Not My.Settings.size.IsEmpty Then
        Me.Size = My.Settings.size
    End If
End Sub