Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7031853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:51:27+00:00 2026-05-28T00:51:27+00:00

Using .NET 4, what is the best way to save an app’s window size

  • 0

Using .NET 4, what is the best way to save an app’s window size and position at closing and use these values to start the app’s window next time it is run?

I prefer not to have to touch any kind of registry but don’t know if there is some kind of app.config (similar to web.config for ASP.NET apps) that I can use for Windows Presentation Foundation apps.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:51:27+00:00Added an answer on May 28, 2026 at 12:51 am

    Description

    Windows Forms

    • Create Properties in Application Settings LocationX, LocationY, WindowWidth, WindowHeight (of type int)
    • Save Location and Size in Form_FormClosed
    • Load and apply Location and Size in Form_Load

    Sample

    private void Form1_Load(object sender, EventArgs e)
    {
        this.Location = new Point(Properties.Settings.Default.LocationX, Properties.Settings.Default.LocationY);
        this.Width = Properties.Settings.Default.WindowWidth;
        this.Height = Properties.Settings.Default.WindowHeight;
    }
    
    private void Form1_FormClosed(object sender, FormClosedEventArgs e)
    {
        Properties.Settings.Default.LocationX = this.Location.X;
        Properties.Settings.Default.LocationY = this.Location.Y;
        Properties.Settings.Default.WindowWidth = this.Width;
        Properties.Settings.Default.WindowHeight = this.Height;
        Properties.Settings.Default.Save();
    }
    

    More Information

    • Application Settings for Windows Forms
    • MSDN – Form.Load Event
    • MSDN – Form.Closed Event

    WPF

    • Create Properties in Application Settings LocationX, LocationY, WindowWidth, WindowHeight (of type double)
    • Save Location and Size in MainWindow_Closed
    • Load and apply Location and Size in MainWindow_Loaded

    Sample

    void MainWindow_Loaded(object sender, RoutedEventArgs e)
    {
        this.Left = Properties.Settings.Default.LocationX;
        this.Top = Properties.Settings.Default.LocationY;
        this.Width = Properties.Settings.Default.WindowWidth;
        this.Height = Properties.Settings.Default.WindowHeight;
    }
    
    void MainWindow_Closed(object sender, EventArgs e)
    {
        Properties.Settings.Default.LocationX = this.Left;
        Properties.Settings.Default.LocationY = this.Top;
        Properties.Settings.Default.WindowWidth = this.Width;
        Properties.Settings.Default.WindowHeight = this.Height;
        Properties.Settings.Default.Save();
    }
    

    More Information

    • Application Settings
    • MSDN – FrameworkElement.Loaded Event
    • MSDN – Window.Closed Event

    I have tested both, WinForms and WPF.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using .NET's Office interop libraries, does anybody know the best way to convert back
What's the easiest/best way to register your program in explorers right-click menu using .NET
If I am using .Net and SQL Server 2008, what is the best way
I am wondering what the best way to send bulk emails is using System.Net.Mail
When using the Net.Sockets.TcpListener, what is the best way to handle incoming connections (.AcceptSocket)
I am using ASP.NET C# with mySql database. What is the best way for
What's the best way to access WSE 2.0 web services from .NET 2.0? Using
What's the best way, using C# or other .NET language, to determine if a
We are using ASP.net MVC. Which of these is the best DI framework Ninject
What is the best way to resize images using .NET, without losing the EXIF

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.