Click here to Skip to main content
13,198,465 members (60,947 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


8 bookmarked
Posted 8 Mar 2011

Very simple way to restore form window to its previous state

, 9 Mar 2011
Rate this:
Please Sign up or sign in to vote.
Very simple way to restore form window to its previous state
To restore form window to its previous state, code only, no settings usage.

Public Class Form1
    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub

    Private Regpath As String = "HKEY_CURRENT_USER\Software\"
    Sub Saveform()
        My.Computer.Registry.SetValue(Regpath & My.Application.Info.Title, "WindowState", Val(Me.WindowState))
        If Me.WindowState <> FormWindowState.Normal Then
        End If
        My.Computer.Registry.SetValue(Regpath & My.Application.Info.Title, "Top", Me.Top)
        My.Computer.Registry.SetValue(Regpath & My.Application.Info.Title, "Left", Me.Left)
        My.Computer.Registry.SetValue(Regpath & My.Application.Info.Title, "Height", Me.Height)
        My.Computer.Registry.SetValue(Regpath & My.Application.Info.Title, "Width", Me.Width)
    End Sub
    Sub Restoreform()
       Me.WindowState = Val(My.Computer.Registry.GetValue(Regpath & My.Application.Info.Title, "WindowState", Me.WindowState))
        If Me.WindowState <> FormWindowState.Normal Then
            'Return 'Not needed, Remove this condition
        End If
        Me.Top = My.Computer.Registry.GetValue(Regpath & My.Application.Info.Title, "Top", Me.Top)
        Me.Left = My.Computer.Registry.GetValue(Regpath & My.Application.Info.Title, "Left", Me.Left)
        Me.Height = My.Computer.Registry.GetValue(Regpath & My.Application.Info.Title, "Height", Me.Height)
        Me.Width = My.Computer.Registry.GetValue(Regpath & My.Application.Info.Title, "Width", Me.Width)
    End Sub
End Class

Aslam Iqbal


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Аslam Iqbal
Software Developer ADDIE Soft Ltd.
Bangladesh Bangladesh
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralReason for my vote of 5 I never really understood how to use... Pin
CircusUgly22-Mar-11 7:37
memberCircusUgly22-Mar-11 7:37 
GeneralRe: Thanks. Pin
Аslam Iqbal22-Mar-11 8:53
memberАslam Iqbal22-Mar-11 8:53 
GeneralJust curious , is it a good practise touching the registry Pin
Aravind Ravindranath Gopi21-Mar-11 22:03
memberAravind Ravindranath Gopi21-Mar-11 22:03 
GeneralRe: yeah, if it's my own computer with full access. Pin
Аslam Iqbal21-Mar-11 22:07
memberАslam Iqbal21-Mar-11 22:07 
GeneralError: My.Computer.Registry.SetValue(Regpath &amp; Regpath &... Pin
Johnny J.8-Mar-11 22:53
memberJohnny J.8-Mar-11 22:53 
GeneralRe: Thanks for that. That wasn't me. maybe that was pasting erro... Pin
Аslam Iqbal9-Mar-11 0:46
memberАslam Iqbal9-Mar-11 0:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171020.1 | Last Updated 9 Mar 2011
Article Copyright 2011 by Аslam Iqbal
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid