Save Windows Form Size

I am developing a piece in VB.NET. In my main form, I create a new form for use as a dialog. I was wondering if there is a way, at the end of a new dialog, to save the size settings for each user (perhaps in a file on his machine, through XML or something like that)

+7
windows winforms preferences savestate
source share
5 answers

you can save it in the settings file and update it in the onclosing event.

to configure goto Project Properties β†’ settings β†’, then configure the type of "dialogsize" type system.drawing.size.

then do it in the form of a dialog:

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 similar to check and use the parameter:

  Dim dlg As MyDialogWindow If My.Settings.DialogSize.IsEmpty Then dlg = New MyDialogWindow() Else dlg = New MyDialogWindow(My.Settings.DialogSize) End If dlg.ShowDialog() 
+7
source share

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

+2
source share

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

Then you should save the current size in the settings when closing.

  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 at boot you apply the size that you saved in the 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 
+2
source share

You can also do this using the user interface provided by the VB.NET IDE itself. In the properties pane for the form, review the item titled "(Application Settings)," and then in the "Linking Properties" section. You can bind almost every property of the form (including size and location) to the parameter value for this application.

0
source share

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

0
source share

All Articles