Brief Description
This lets you save and load these main settings(Form Size(Width and Height), Form Location and form WindowState(Maximized or not) for a desired form. Adds professionalism!
Step 1
• Open your Program Properties.- This can be opened via multiple ways.
○ Project > "Your Project Name" Properties...
○ Double click My Project, located at the top of your Solution Explorer under "Your Project Name"
Step 2
• Go to the Settings Tab and add in these settings○ Name: frmWidth Type: Integer Value: 500
○ Name: frmHeight Type: Integer Value: 500
○ Name: frmMax Type: Boolean Value: False
○ Name: frmLocation Type: System.Drawing.Point Value: 0, 0
★ Note: You can change the Value to anything you want as well as the Name
Step 3
• Now Add in these codes
Code:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If My.Settings.frmMax = True Then
WindowState = FormWindowState.Maximized
Else
Me.Location = My.Settings.frmLocation
Height = My.Settings.frmHeight
Width = My.Settings.frmWidth
End If
End Sub
Code:
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
If WindowState = FormWindowState.Maximized Then
My.Settings.frmMax = True
My.Settings.frmWidth = 500
My.Settings.frmHeight = 500
Else
My.Settings.frmLocation = Me.Location
My.Settings.frmMax = False
My.Settings.frmWidth = Width
My.Settings.frmHeight = Height
End If
My.Settings.Save()
End Sub
Final Step (Step 4)
• Build your project!○ Press F5 to Debug
○ Debug > Start Debugging
○ Build > Build "Your Project Name"