Results 1 to 3 of 3
  1. #1
    DawgiiStylz's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Location
    Dawg House
    Posts
    7,811
    Reputation
    219
    Thanks
    2,896
    My Mood
    Tired

    Saving a Form Size, Location, and WindowState

    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"
    Last edited by Hassan; 07-18-2012 at 12:50 PM. Reason: Added My.Settings.Save() to Form_Closing Event

  2. #2
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    You forgot to save the settings at the end of the Form_Closing event. Modified your code.

  3. #3
    DawgiiStylz's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Location
    Dawg House
    Posts
    7,811
    Reputation
    219
    Thanks
    2,896
    My Mood
    Tired
    Thats not needed if you have this checked (In this situation you don't need to add that. If it was a settings menu and you used your settings to change things in your application, then that'll be needed)

    Quote Originally Posted by Hassan View Post
    You forgot to save the settings at the end of the Form_Closing event. Modified your code.

Similar Threads

  1. The Ender Realm, Stronghold locators and more
    By Elocrypt. in forum Minecraft Discussions
    Replies: 3
    Last Post: 10-07-2011, 06:47 PM
  2. [Request] Change Form Size [solved]
    By muddy175 in forum Visual Basic Programming
    Replies: 8
    Last Post: 06-10-2011, 10:55 AM
  3. [Epic]SPG]P90 SE to MP7 Steel Real Sizing,sound and Texture
    By spiderpig666 in forum Combat Arms Mods & Rez Modding
    Replies: 17
    Last Post: 09-26-2010, 09:44 PM
  4. 3 siggys-Spiderman, Saving Private Ryan, and an Irish siggy
    By m164life in forum Art & Graphic Design
    Replies: 9
    Last Post: 04-26-2008, 04:59 AM
  5. Look he have stoled my signature and location
    By xtrylanx in forum General
    Replies: 23
    Last Post: 08-22-2007, 09:32 PM