Click here to Skip to main content
15,912,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys..

I dont know why I'm suffering window resizing problem. The requirement is
user will re-size the window From run time, when s/he exit and re run the application it will load with the previous setting, For example, window height, weight, start up position etc.

Can any one help me to resolve this?
Posted

this CP article[^] may be good starting position. Make sure to read the comments as well.
 
Share this answer
 
Comments
[no name] 22-Aug-10 4:49am    
Reason for my vote of 5
Thanks..
This might also help[^].
 
Share this answer
 
Comments
fjdiewornncalwe 8-Mar-11 16:03pm    
This is my pick for the best solution. +5
Abhinav S 8-Mar-11 23:47pm    
Thank you Marcus.
I know you better can convert this VB.NET code in C#.
It's very simple to restore a form's size & positions.
Codes only, no settings usage.

VB
Public Class Form1
    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Saveform()
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Restoreform()
    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
            Return
        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()
        'Dim xx = My.Computer.Registry.GetValue(Regpath & My.Application.Info.Title, "WindowState", Me.WindowState)
        Me.WindowState = Val(My.Computer.Registry.GetValue(Regpath & My.Application.Info.Title, "WindowState", Me.WindowState))
        If Me.WindowState <> FormWindowState.Normal Then
            'Return
        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


I'm confused about the article: Restore Form Position and Size in C#[^]
Why it is so complex for a simple operation.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900